Postgresql – “undefined function pg_pconnect()” when connecting to Postgres from CodeIgniter

codeigniterconnectionspostgresql

I just installed Postgresql and pgadmin in my Ubuntu system. I can create a database from the pgadmin interface and everything seems ok, but when I try to connect to the database from my CodeIgniter application it cannot not connect. It shows an error like:

An uncaught Exception was encountered

Type: Error

Message: Call to undefined function pg_pconnect()

Filename: /my codeigniter application
path/system/database/drivers/postgre/postgre_driver.php

My database configuration is:

$db['postgres_db'] = array(
    'dsn'      => '', 

    'hostname' => 'localhost',
    'username' => 'postgres',
    'password' => '1234',
    'database' => 'finance',
    'dbdriver' => 'postgre',
    'dbprefix' => '',
    'pconnect' => TRUE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE,
    'port'     => 5432
);

How can I resolve this problem?

Best Answer

    $db['default'] = array(
    'dsn'   => '',
    'hostname' => 'pgsql:host=localhost;dbname=Absences_DB',
    'username' => 'postgres',
    'password' => 'XXX',
    'database' => 'Absences_DB',
    'dbdriver' => 'pdo',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

Make sure you have the PDO driver enabled in PHP.