2
votes

I have an issue with regarding the connection between Codeigniter & PDO_PGSQL

I have tried to connect in RedHat 6.8 Server OS.

My config file:

$active_group = 'default';
$query_builder = TRUE;

$db['default']['hostname'] = 'pgsql:host=<myip>;dbname=shlydb;';
$db['default']['username'] = 'root';
$db['default']['password'] = '123';
$db['default']['database'] = 'shlydb';
$db['default']['dbdriver'] = 'pdo';
$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']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
$db['default']['port'] = 5432;

also attaching the db_connect function..

 public function db_connect($persistent = FALSE)
  {
    $this->options[PDO::ATTR_PERSISTENT] = $persistent;

    try
    {
        return new PDO($this->dsn, $this->username, $this->password, $this->options);
    }
    catch (PDOException $e)
    {
        if ($this->db_debug && empty($this->failover))
        {       
            $this->display_error($e->getMessage(), '', TRUE);
        }

        return FALSE;
    }
}

But showing an error while running,

A PHP Error was encountered

Severity: Warning

Message: PDO::__construct(): SQLSTATE[IM001]: Driver does not support this function: driver does not support setting attributes

Filename: pdo/pdo_driver.php

Line Number: 133

1

1 Answers

0
votes

Hi the config should look like this:

    $db['default']['dsn'] = 'pgsql:host=<myip>;port=5432;dbname=shlydb';
    $db['default']['hostname'] = '<myip>';
    $db['default']['username'] = 'root';
    $db['default']['password'] = '123';
    $db['default']['database'] = 'shlydb';
    $db['default']['dbdriver'] = 'pdo';
    $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']['swap_pre'] = '';
    $db['default']['autoinit'] = TRUE;
    $db['default']['stricton'] = FALSE;
    $db['default']['port'] = 5432;