Welcome Guest, Not a member yet? Register   Sign In
CI can not connect to PostgreSQL database
#1

[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-gui...ction.html
#2

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

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

[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-gui...ction.html
#4

[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.




Theme © iAndrew 2016 - Forum software by © MyBB