0

I'm trying to connect a postgres db but I get this error

my database.php file I have the default connection too add

$db['newdb'] = array(
        'dsn'   => 'pgsql:host=192.xxx.x.xxx;port=5432;dbname=dbname',
        'hostname' => 'localhost',
        'username' => 'username',
        'password' => 'password',
        'database' => 'dbname',
        'dbdriver' => 'pgsql',
        '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
    );

here my modal

<?php
class Model extends CI_Model {

 private $db_b;

 function __construct(){
  $this->db_b = $this->load->database('newdb', TRUE);
 }


 public function getData()
 {

   $this->db_b->order_by('ad_reference_id', 'asc');
   $query = $this->db_b->get('table');
   if ($query->num_rows() > 0) {
     return $query->result();
   } else {
     return false;
   }
 }
}

I got this ERROR An Error Was Encountered

Invalid DB driver

Why is it not working? :(

1
  • change 'dbdriver' => 'pgsql' to 'dbdriver' => 'pdo' Commented Jun 21, 2018 at 18:01

1 Answer 1

1

You have designated a driver that does not exist with this

'dbdriver' => 'pgsql',

I think what you want is

'dbdriver' => 'postgre',

Edit: Checking PHP configuration

Create a controller called Info.php Here's the code for it.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Info extends CI_Controller
{
    public function index()
    {
        phpinfo();
    }
}

Direct the browser to yoursite.com/info and search the resulting page for postgres.

Sign up to request clarification or add additional context in comments.

6 Comments

Type: Error Message: Call to undefined function pg_connect() Filename: /var/www/html/test/system/database/drivers/postgre/postgre_driver.php Line Number: 154
Well that is weird because pg_connect() is a PHP function. You certain that your PHP has PostgreSQL installed?
how can I check that? I'm on linux Mint
See the added info in the answer.
could affect in the server they have php 5.0 and Im working with codeigniter 3.1.9
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.