Cannot connect to PG database

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ijf99
Forum Newbie
Posts: 2
Joined: Wed Feb 03, 2010 4:11 am

Cannot connect to PG database

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Cannot connect to PG database

Post by VladSun »

Put this line at the top of your file:

Code: Select all

error_reporting(E_ALL);
There are 10 types of people in this world, those who understand binary and those who don't
ijf99
Forum Newbie
Posts: 2
Joined: Wed Feb 03, 2010 4:11 am

Re: Cannot connect to PG database

Post 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
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Cannot connect to PG database

Post 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 ;)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply