Re: Connecting to database using pg_connect

Lists: pgsql-novice
From: <Gene(dot)Brumm(at)thomson(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Connecting to database using pg_connect
Date: 2005-03-29 18:49:14
Message-ID: D7E3DC215167A3479A7B771C33BC0EBE06ED666B@tlrusmneagmbx01.erf.thomson.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

I am having trouble connecting to a PostgreSQL database using the
following code. The first echo message appears but none of the others. I
can connect fine using psql. What am I doing wrong?

<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
echo 'Before pg_connect ...';
$hDB = @pg_connect("dbname=TestDB user=geneb password=dynamo!");
echo 'Before if ...';
if(! is_resource($hDB)) {
throw new Exception('Unable to connect to the database.');
}
echo 'Got here ...';
?>
</body>
</html>


From: John DeSoi <desoi(at)pgedit(dot)com>
To: <Gene(dot)Brumm(at)thomson(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Connecting to database using pg_connect
Date: 2005-03-30 05:36:50
Message-ID: B7082955-A0DD-11D9-ACC4-000A95B03262@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice


On Mar 29, 2005, at 1:49 PM, <Gene(dot)Brumm(at)thomson(dot)com> wrote:

> I am having trouble connecting to a PostgreSQL database using the
> following code. The first echo message appears but none of the others.
> I can connect fine using psql. What am I doing wrong?

Is your database name really capitalized like you have it in the
connect string? Have you double checked that pgsql support is compiled
into your php implementation? If you are testing this with a web
server, you might try just running it from the command line to see if
you get a better error description.

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL