pobox@verysmall.org wrote:
> Richard Huxton wrote:
>> Did you try pg_last_error()?
>
> pg_last_error() does not seem to work. It requires connection as
> parameter, so if pg_connect() fails - it has nothing to operate on.
>
> Or am I missing something?
No, I was. I've gone back and re-read your original message.
I'm a bit surprised you're not seeing an error message when the
connection fails. Try some code like this:
<?php
ini_set('track_errors','on');
$conn = @pg_connect("host=localhost dbname=nosuchdb user=richardh");
echo "Connection result: ";
print_r($conn);
echo "<hr>";
if ($conn===false) {
echo "Connection failed: ";
print_r($php_errormsg);
echo "<hr>";
}
?>
Without the "track_errors" and @ on the front of pg_connect you should
get a php error. You might want an error-handling function.
>> Are you logging connection attempts/failures? Details in the manuals.
>
> Checked the manual, but found only parameter to log the successful
> connections.
>
> Is there such to log the failed connection attempts (incl. the reason)?
It's an error, so you'll see an error logged.
2007-04-26 09:16:00 BST nosuchdb 1 FATAL: database "nosuchdb" does not
exist
Of course, if you're connecting to the wrong port, or wrong machine then
the server will never see the connection, so it can't log that.
--
Richard Huxton
Archonet Ltd