Re: pg_last_error() doesn't return connection errors

Поиск
Список
Период
Сортировка
От Andrew McMillan
Тема Re: pg_last_error() doesn't return connection errors
Дата
Msg-id 1282862673.3487.3674.camel@happy.home.mcmillan.net.nz
обсуждение исходный текст
Ответ на pg_last_error() doesn't return connection errors  (Frank Naude <naudefj@gmail.com>)
Ответы Re: pg_last_error() doesn't return connection errors  (Frank Naude <naudefj@gmail.com>)
Список pgsql-php
On Thu, 2010-08-26 at 13:44 +0200, Frank Naude wrote:
> Hi,
>
> I can successfully connect to PostgreSQL (pgsql extension). However,
> when I make a deliberate mistake, I'm unable to capture the connection
> error with pg_last_error() as one would with the *_last_error()
> functions of other database extensions.
>
> Here is an example:
>
> <?php
> $c = pg_connect('host=127.0.0.1 user=postgres password=xxx
> dbname=yyy') or var_dump( pg_last_error() );
> ?>
>
> The following output (with warnings) is returned:
>
> Warning: pg_connect() [function.pg-connect]: Unable to connect to
> PostgreSQL server: FATAL: password authentication failed for user
> "postgres" in ..
> Warning: pg_last_error() [function.pg-last-error]: No PostgreSQL link
> opened yet in ...
> bool(false)
>
> One would expect pg_last_error() to return "password authentication
> failed" instead of FALSE!

Hi Frank,

Presumably pg_last_error() doesn't do anything useful until after the
database connection has been made...

That behaviour doesn't seem particularly unnatural to me, really, though
this seems an unlikely place to be posting a bug about it.  If it's a
problem for you perhaps you should file a bug with the developer.

Alternatively, does pg_errormessage() have the same flaw, or does that
give you the error details that you're after?  That's what I use in my
own code, although I note that in my own code I only log the fact of
connection failure, without logging the reason, and I use that for
getting the error when a query fails.  Perhaps something I should
improve :-)

Cheers,
                    Andrew.

--
------------------------------------------------------------------------
andrew (AT) morphoss (DOT) com                            +64(272)DEBIAN
         Flexibility is overrated.  Constraints are liberating.
------------------------------------------------------------------------


Вложения

В списке pgsql-php по дате отправления:

Предыдущее
От: Frank Naude
Дата:
Сообщение: pg_last_error() doesn't return connection errors
Следующее
От: Frank Naude
Дата:
Сообщение: Re: pg_last_error() doesn't return connection errors