PHP pg_connect

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

PHP pg_connect

numb3rs-2
When this fails, I get a useful error print:

$dbconn = pg_connect($connection_str);

Ouput:

Warning: pg_connect() [function.pg-connect]: Unable to connect to
PostgreSQL server: FATAL: password authentication failed for user
"postgres1" in ...

How do I capture this error and handle the printing myself?  I want to
be able to know why it failed... ie password in this case.

Thanks,
Vince.

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend
Reply | Threaded
Open this post in threaded view
|

Re: PHP pg_connect

Hannes Dorbath
On 17.07.2007 09:13, Vince wrote:

> When this fails, I get a useful error print:
>
> $dbconn = pg_connect($connection_str);
>
> Ouput:
>
> Warning: pg_connect() [function.pg-connect]: Unable to connect to
> PostgreSQL server: FATAL: password authentication failed for user
> "postgres1" in ...
>
> How do I capture this error and handle the printing myself?  I want to
> be able to know why it failed... ie password in this case.

This is a PHP, not a PostgreSQL question.

if (!pg_connect()) {
   if (preg_match('/authentication\sfailed/', pg_last_error())) {
     echo "Oh dear, you lost your password?\n";
   } else if (true) {
     echo "OMG, something else went wrong!\n";
   }
}


--
Regards,
Hannes Dorbath

---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings
Reply | Threaded
Open this post in threaded view
|

Re: PHP pg_connect

Hannes Dorbath
On 17.07.2007 09:45, Hannes Dorbath wrote:
> This is a PHP, not a PostgreSQL question.

Well, pg_last_error() might not return something in that case. You can
create a custom error handler if the message is important for you.


--
Regards,
Hannes Dorbath

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

               http://archives.postgresql.org/
Reply | Threaded
Open this post in threaded view
|

Re: PHP pg_connect

Matthew Terenzio
In reply to this post by numb3rs-2

On Jul 17, 2007, at 3:13 AM, Vince wrote:

> When this fails, I get a useful error print:
>
> $dbconn = pg_connect($connection_str);
>
> Ouput:
>
> Warning: pg_connect() [function.pg-connect]: Unable to connect to
> PostgreSQL server: FATAL: password authentication failed for user
> "postgres1" in ...
>
> How do I capture this error and handle the printing myself?  I want to
> be able to know why it failed... ie password in this case.

If I understand correctly:

http://us.php.net/manual/en/function.pg-result-error.php




>
> Thanks,
> Vince.
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 6: explain analyze is your friend
>


---------------------------(end of broadcast)---------------------------
TIP 5: don't forget to increase your free space map settings