0

I'm used to Codeigniter with mysql(i) but I have a customer who needs PostgreSQL to be connected. I tried the usual settings and added the specific port for Postgre but I get this error:

Unable to connect to your database server using the provided settings.

enter image description here

My code is simply this:

$active_group = (ENVIRONMENT == 'development') ? 'offline' : 'online';
//Set to 'development' in file: index.php    
$active_record = TRUE;

/**
 * OFFLINE CONFIGURATION
 */

$db['offline']['hostname'] = 'localhost';
$db['offline']['username'] = 'root';
$db['offline']['password'] = 'root';
$db['offline']['database'] = 'testing';
$db['offline']['dbdriver'] = 'postgre';
$db['offline']['dbprefix'] = '';
$db['offline']['pconnect'] = TRUE;
$db['offline']['db_debug'] = TRUE;
$db['offline']['cache_on'] = FALSE;
$db['offline']['cachedir'] = '';
$db['offline']['char_set'] = 'utf8';
$db['offline']['dbcollat'] = 'utf8_general_ci';
$db['offline']['swap_pre'] = '';
$db['offline']['autoinit'] = TRUE;
$db['offline']['stricton'] = FALSE;
$db['offline']['port'] = 5432;

/**
 * ONLINE CONFIGURATION
 */
$db['online']['hostname'] = '?';
$db['online']['username'] = '?';
$db['online']['password'] = '?';
$db['online']['database' .... 
//Continues with online configuration...     

Now I'm using the offline configuration for now and this is not working showing the error above. I did try to set "db_debug" to FALSE and that works but I feel like is just skimping the point and I'll never get database error shown which I need in offline mode...

I have pgAdmin open and is connected to the same database and is working ok. Any hint on this?

3 Answers 3

1

IF there is problem with

$db['offline']['dbdriver'] = 'postgre'

then use

$db['offline']['dbdriver'] = 'pdo' 

instead of postgres.

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

Comments

0

Ok, after looking there was an error in the username. The configuration was not done by me and the person writing the original username put postresinstead of root as was agreed.

Unfortunately the CI class doesn't output that specific error but just a general "Unable to connect to your database server using the provided settings."

Sorry for the post. Thanks to everybody.

Comments

0

According to the documentation page for the CodeIgniter DB drivers, the available values are mysql, postgres, odbc. So, change the $db['offline']['dbdriver'] value from postgre to postgres and try again. It should connect without problems as long as your username and password are right.

Edit: There are other sources which suggest that the driver name is actually postgre instead of postgres, contrary to the documentation (that's a shame, really). So I'd suggest that you try with postgres and postgresql. If it's still not working, check your php.ini, and check if you have uncommented the PostgreSQL module (search for extension=php_pgsql line).

The module is called php_pgsql.so on Linux boxes, and php_pgsql.dll on Windows.

If you see it and it has ; before the line, remove the ; and restart the Apache server (it should be available on Windows). If not, you need to install it first and then add it to php.ini. The installation varies from distro to distro, but there are plenty of tutorials on how to install it on a Linux box.

1 Comment

Tku. I did try but that's not working. Error: A PHP Error was encountered Severity: Warning Message: require_once(.../system/database/drivers/postgres/postgres_driver.php): failed to open stream: No such file or directory Filename: database/DB.php Line Number: 140 Looks like is actually postgre and not postgres from here: ellislab.com/forums/viewthread/131807/#925186

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.