Page 1 of 1

Cannot connect to PG database

Posted: Wed Feb 03, 2010 4:25 am
by ijf99
Hello folks,

Bit of a newbie question, sorry if it's very simple. I'm writing my first PHP script which I want to connect to a Postgres DB, however it seems to fall at the first hurdle. Any suggestions on what I'm doing wrong would be appreciated.

I'm using Apache 2, PHP 4, RHEL 4, Postgres 7.4.

The code I'm using is:

<?php
echo "<h1>Connection Information</h1>";
echo "no error";
$connection = pg_connect("dbname=db_1 user=ijf99 host=ijflnx");
echo "you got this far";
if (!$conn) {
echo "An error occured.\n";
exit;
}
?>

The Connection Info & No error bits are displayed, but after that there is nothing.

Any help appreciated :banghead:

Thanks!
Ian

Re: Cannot connect to PG database

Posted: Wed Feb 03, 2010 7:15 am
by VladSun
Put this line at the top of your file:

Code: Select all

error_reporting(E_ALL);

Re: Cannot connect to PG database

Posted: Wed Feb 03, 2010 8:12 am
by ijf99
Thanks for that Vlad. I ran it and nothing happened. Looking in /var/log/messages pg_connect() is unrecognised and it appears I don't have the file libpq.so... this may be my problem

Re: Cannot connect to PG database

Posted: Wed Feb 03, 2010 8:26 am
by VladSun
ijf99 wrote:Thanks for that Vlad. I ran it and nothing happened. Looking in /var/log/messages pg_connect() is unrecognised and it appears I don't have the file libpq.so... this may be my problem
Definitely that could be a problem ;)