Welcome Guest, Not a member yet? Register   Sign In
CI 1.6 with Postgres 8.2 database connection problem
#1

[eluser]fdog[/eluser]
Can't connect to postgres. All services are running and the data base and tables were created. The port is right. (triple checked).

database.php:
Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "user";
$db['default']['password'] = "password";
$db['default']['database'] = "mydb";
$db['default']['dbdriver'] = "postgre";
$db['default']['dbprefix'] = "";
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = "";
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
$db['default']['port'] = 5432;

controller:
Code:
class Fooclass extends Controller {

function Fooclass()
{
    parent::Controller();
    $this->load->helper('html');
    $this->load->helper('url');
    $this->load->database(); //also tried in autoload.php (not at the same time)
}

function index()
{                
    $this->load->view('includes/top_view');
    $this->load->view('body_view');
    $this->load->view('includes/sidebar_view');
    $this->load->view('includes/footer_view');
}
}
The weirdest is that there is no error message, only a blank page. If I remove the $this->load->database() line, the thing works like a charm.
#2

[eluser]Seppo[/eluser]
Can you connect if you create a new PHP file, outside CI?
Something like this
Code:
<?php
$connection = pg_pconnect("host=localhost port=5432 dbname=mydb user=user password=password");
echo is_resource($connection) ? 'Success' : 'Fail';
?>

(trying to see if it's a CI issue or a PHP-postgre thing.
#3

[eluser]fdog[/eluser]
Thanks a lot Seppo. I didn't have installed the PostgreSQL module for php5.
#4

[eluser]Seppo[/eluser]
Cool =)
No problem
#5

[eluser]fdog[/eluser]
Now I'm getting this error when I to try to retrieve fields from a table:

controller:
Code:
$data['query'] = $this->db->get('entries');

error:
Code:
You have an error in your SQL syntax near «)» LINE 2: FROM ("entries") ^

SELECT * FROM ("entries")

I even get something very similar with scaffolding. Is it a bug?

[Edit]: It was a bug Tongue. This thread helped me solved it.




Theme © iAndrew 2016 - Forum software by © MyBB