CodeIgniter Forums
CI can not connect to PostgreSQL database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: CI can not connect to PostgreSQL database (/showthread.php?tid=57511)



CI can not connect to PostgreSQL database - El Forum - 03-19-2013

[eluser]Unknown[/eluser]
Hi!

I'm a new bie of CI Framework. I've read CI document and follow step by step from it. Instead of using MySQL database, I use PostgreSQL.

But I can connect to PostgreSQL database. I don't know why? Could you give me some how to debug CI framework?

I almost used all latest version of software:
CentOS 6.4
Apache 2.4.4
PHP 5.4.13
PostgreSQL 9.2.3

Bellow is my database.php file:
---------------------------------
/*
| -------------------------------------------------------------------
| TEST ENVIROMENT
| -------------------------------------------------------------------
*/
$db['test']['hostname'] = 'localhost';
$db['test']['username'] = 'postgres';
$db['test']['password'] = 'P@ssw0rd';
$db['test']['database'] = 'helloworld';
$db['test']['dbdriver'] = 'postgre';
$db['test']['port'] = '5432';
$db['test']['dbprefix'] = '';
$db['test']['pconnect'] = TRUE;
$db['test']['db_debug'] = FALSE;
$db['test']['cache_on'] = FALSE;
$db['test']['cachedir'] = '';
$db['test']['char_set'] = 'utf8';
$db['test']['dbcollat'] = 'utf8_general_ci';
$db['test']['swap_pre'] = '';
$db['test']['autoinit'] = TRUE;
$db['test']['stricton'] = FALSE;
/*
| -------------------------------------------------------------------
| DEBUG PGSQL CONNECTION
| -------------------------------------------------------------------
| http://ellislab.com/forums/viewthread/207916/
|
*/
echo '<pre>';
print_r($db['test']);
echo '</pre>';

echo 'Trying to connect to database: ' .$db['test']['database'];
$host = $db['test']['hostname'];
$user = $db['test']['username'];
$pass = $db['test']['password'];
$port = $db['test']['port'];
$db = $db['test']['database'];

$conn_str = "host=$host port=$port dbname=$db user=$user password=$pass";
echo '<br />Connection string: ' . $conn_str;
$dbh = pg_connect($conn_str)
or die ('<br />Could not connect to server!' . pg_last_error($dbh));

echo '<br /> Connected OK!' ;
die( '<br />File: ' .__FILE__ . '--&gt; Line: ' .__LINE__);
//----------------------------

The tutorial I followed:
http://ellislab.com/codeigniter/user-guide/tutorial/news_section.html


CI can not connect to PostgreSQL database - El Forum - 03-20-2013

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums.

I assume you're getting an error. What error are you getting?


CI can not connect to PostgreSQL database - El Forum - 03-20-2013

[eluser]Unknown[/eluser]
Thank for your concern, TheFuzzy0ne!

I have some trouble in connecting to postgresql database! I tested the tuts bellow with MySQL, it was successful! But with PostgreSQL, it displayed nothing - a blank page!!! And I don't know how to debug it?

Could u show me how to debug CI framework?

http://ellislab.com/codeigniter/user-guide/tutorial/news_section.html


CI can not connect to PostgreSQL database - El Forum - 03-20-2013

[eluser]TheFuzzy0ne[/eluser]
At the top of your index.php file, put the following:
Code:
ini_set('display_errors', '1');
error_reporting(E_ALL);

That should enable error reporting.

Make sure you remove that before your site goes live.

In ./application/config/database.php, find the following lines:
Code:
$db['default']['db_debug'] = FALSE;
$db['default']['stricton'] = FALSE;

and set them both to TRUE.

Again, make sure they're both set to FALSE when your app goes live.

Blank pages are usually caused by an error being thrown whilst error reporting is disabled, or because you're outputting a trailing space or tab after a closing PHP tag in your controller or another non-view file. Because of this, it's recommended you omit the closing PHP tag at the end of your files.

Hope this helps.