Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

sqldatasource dal, wwwxxxenden, convert raid5 to raid 10 mdadm, apache force chunked, nrao wwwxxx, xxxxxdup, procmail change subject header, wwwXxx not20, Wwwxxx.doks sas, linux raid resync after reboot

Links

XODOX
Impressum

#1: pg_last_error() doesn"t return connection errors

Posted on 2010-08-26 13:44:44 by Frank Naude

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!

Best regards.

Frank

--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Report this message

#2: Re: pg_last_error() doesn"t return connection errors

Posted on 2010-08-27 00:44:33 by Andrew McMillan

--=-vq+W4TC3b+4EHX5F3VeE
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Thu, 2010-08-26 at 13:44 +0200, Frank Naude wrote:
> Hi,
>=20
> 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.
>=20
> Here is an example:
>=20
> <?php
> $c =3D pg_connect('host=3D127.0.0.1 user=3Dpostgres password=3Dxxx
> dbname=3Dyyy') or var_dump( pg_last_error() );
> ?>
>=20
> The following output (with warnings) is returned:
>=20
> 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)
>=20
> 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.

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


--=-vq+W4TC3b+4EHX5F3VeE
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iQIcBAABAgAGBQJMdu5OAAoJEOr8/r+P646/WqUP/1StfwqkOx/FoKkrr1MV ajqW
fi52xNX2QtKlew4ZiOIOOphyFkVIY6krOMIM6AyH6lVIU1gxBC1lC2JnYHJd cAOq
xsNNZwwAG46+5Rq+YtMRT89YMd3nPlSMZDMGF1gc2V3MoGmvit4skyzUuabY am6m
dx5CbmcIs9eUAoB2sBvCnS56f/NkEcTxyRuvGa3QuNyqi+hP0V5VXqEaykW6 xyd2
wsaYvb/VT8D7kXSNOnIhs/JibwUDdCeIs0iekNdhDQNeYhTRg9p9m3XQBIF0 ehgm
vVV50QeSwoLPDGZBZPilCiao7q6x578gqNwrSyI1zqTQUFeH0o/ajTE3J8vB BLR6
OlFAgGe9tqi2xJ5LDJ6H7X6MoXMNABcyqjUO0bJGKlbj+h73BQOqFpDvR+7R cTKc
vTX3TnAu82LIn9HfEcTX6kaFdOQztj4Bu5z9mGXFoyI2/OCnkiHYUKlgrg8S ep0d
M0zLl6WKEs0gZivACN5uzlGEpXggADrphHB3jS+TwKSmQko7KWIcZ17p/+n1 Luzx
5PTvRr6XtnM0yGo7OHpCXcS8ogWVgmK989b9/h2YlyruDL0uXFX2+HptgHYl EJQX
umGaRb+WIKxbI/KN5iGR1eBeYE7WeCSi3LZTjXrXbcQ7h2Xef/7yHFo5RNFx xhAD
qP0ZZvDeGCAUDaHEy6Tg
=Ri52
-----END PGP SIGNATURE-----

--=-vq+W4TC3b+4EHX5F3VeE--

Report this message

#3: Re: pg_last_error() doesn"t return connection errors

Posted on 2010-08-27 11:17:18 by Frank Naude

Hi Andrew,

Thank you very much for the reply!

> Alternatively, does pg_errormessage() have the same flaw...?

Unfortunately pg_errormessage() doesn't work either. It returns:

Warning: pg_errormessage() [function.pg-errormessage]: No PostgreSQL
link opened yet in...

> That behaviour doesn't seem particularly unnatural to me,...

It is inconsistent with how the other DB modules behave. I can provide
you with some examples if it would help.

Best regards.

Frank

--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Report this message

#4: Re: pg_last_error() doesn"t return connection errors

Posted on 2010-08-27 12:22:40 by Grzegorz Ornoch

--0022152d5fb5cdf79e048ecb7fcc
Content-Type: text/plain; charset=UTF-8

Hi
Try this function

/**
* @name pg_error
*
* @param pg resource result
* @param pg resource connection
*
* @return string content of the error pg
*
*/
function pg_error($result, $connection)
{
return ($result === false ? pg_last_error($connection) :
pg_result_error($result));
}
--
Regards
Grzegorz Ornoch


On Fri, Aug 27, 2010 at 11:17 AM, Frank Naude <naudefj@gmail.com> wrote:

> Hi Andrew,
>
> Thank you very much for the reply!
>
> > Alternatively, does pg_errormessage() have the same flaw...?
>
> Unfortunately pg_errormessage() doesn't work either. It returns:
>
> Warning: pg_errormessage() [function.pg-errormessage]: No PostgreSQL
> link opened yet in...
>
> > That behaviour doesn't seem particularly unnatural to me,...
>
> It is inconsistent with how the other DB modules behave. I can provide
> you with some examples if it would help.
>
> Best regards.
>
> Frank
>
> --
> Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-php
>

--0022152d5fb5cdf79e048ecb7fcc
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div>Hi</div><div>Try this function</div><div><div><br></div><div><font cla=
ss=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">à=C2=
=A0 à/**</font></div><div><font class=3D"Apple-style-span" face=3D"&#3=
9;courier new&#39;, monospace">àà à * @name à àpg_=
error</font></div>

<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">àà à *</font></div><div><font class=3D"Apple-style-span=
" face=3D"&#39;courier new&#39;, monospace">àà à * @param =
à pg resource result</font></div><div>

<font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=
àà à * @param à pg resource connection</font></div><div=
><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace"=
>àà à *</font></div><div>

<font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monospace">=
àà à * @return àstring à</font><span class=3D"Appl=
e-style-span" style=3D"font-size: 12px; "><font class=3D"Apple-style-span" =
face=3D"&#39;courier new&#39;, monospace">content of the error pg</font></s=
pan></div>

<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">àà à *</font></div><div><font class=3D"Apple-style-span=
" face=3D"&#39;courier new&#39;, monospace">àà à */</font></=
div><div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, mo=
nospace">àà àfunction pg_error($result, $connection)</font><=
/div>

<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">àà à{</font></div><div><font class=3D"Apple-style-span"=
face=3D"&#39;courier new&#39;, monospace">àà à à =C2=
=A0return ($result ===3D false ? pg_last_error($connection) : pg_result=
_error($result));</font></div>

<div><font class=3D"Apple-style-span" face=3D"&#39;courier new&#39;, monosp=
ace">àà à}</font></div></div>--<br clear=3D"all">Regards<br>=
à Grzegorz Ornoch<br>
<br><br><div class=3D"gmail_quote">On Fri, Aug 27, 2010 at 11:17 AM, Frank =
Naude <span dir=3D"ltr">&lt;<a href=3D"mailto:naudefj@gmail.com">naudefj@gm=
ail.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D=
"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

Hi Andrew,<br>
<br>
Thank you very much for the reply!<br>
<br>
&gt; Alternatively, does pg_errormessage() have the same flaw...?<br>
<br>
Unfortunately pg_errormessage() doesn&#39;t work either. It returns:<br>
<br>
Warning: pg_errormessage() [function.pg-errormessage]: No PostgreSQL<br>
link opened yet in...<br>
<br>
&gt; That behaviour doesn&#39;t seem particularly unnatural to me,...<br>
<br>
It is inconsistent with how the other DB modules behave. I can provide<br>
you with some examples if it would help.<br>
<div><div></div><div class=3D"h5"><br>
Best regards.<br>
<br>
Frank<br>
<br>
--<br>
Sent via pgsql-php mailing list (<a href=3D"mailto:pgsql-php@postgresql.org=
">pgsql-php@postgresql.org</a>)<br>
To make changes to your subscription:<br>
<a href=3D"http://www.postgresql.org/mailpref/pgsql-php" target=3D"_blank">=
http://www.postgresql.org/mailpref/pgsql-php</a><br>
</div></div></blockquote></div><br>

--0022152d5fb5cdf79e048ecb7fcc--

Report this message

#5: Re: pg_last_error() doesn"t return connection errors

Posted on 2010-08-27 14:26:33 by Frank Naude

Hi Grzegorz,

On Fri, Aug 27, 2010 at 12:22 PM, Grzegorz Ornoch <yanegorz@gmail.com> wrote:
> Try this function...

Nice function, but since we cannot connect, and we do not have a
connection, it wouldn't help much either.

Best regards.

Frank

--
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Report this message

#6: Re: pg_last_error() doesn"t return connection errors

Posted on 2010-08-27 14:33:41 by Frank Naude

Hi Andrew,

On Fri, Aug 27, 2010 at 2:01 PM, Andrew McMillan <andrew@morphoss.com> wrot=
e:
> Since I've migrated to PDO, and only have a bit of legacy stuff around
> that uses pg_* I don't think it will do me any good at all! =A0I really
> try to let other people do all of the coding against other databases, so
> I can luxuriate in the One True SQL :-)

I'm fully aware that the pdo_pgsql works as it should - here is an example:

try {
$c =3D new PDO('pgsql:host=3D127.0.0.1 user=3Dpostgres password=3Dxxx
dbname=3Dyyy', 'postgres', 'xxx');
} catch (PDOException $e) {
var_dump( $e->getMessage() );
}

However, the pgsql driver needs some updating or should be deprecated.

Best regards.

Frank

--=20
Sent via pgsql-php mailing list (pgsql-php@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-php

Report this message