From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Cima <ruel(dot)cima(at)facinf(dot)uho(dot)edu(dot)cu> |
Cc: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: error handling |
Date: | 2005-04-13 15:16:04 |
Message-ID: | 20050413151604.GA53810@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Wed, Apr 13, 2005 at 01:46:24AM -0400, Cima wrote:
>
> im working with php 4 and postgresql 8 and i would like to know how to
> handle certain errors generated. in postgresql, i've written a stored
> function that selects a record from a table and in case no record is found i
> 'raise an exception'. fine, now in my php script i call that the stored
> function which works properly when there is a record but when the record
> doesnt exist, i would like to be able to place my own error message and not
> e.g 'fatal error, .....'. how do i capture(in php) the exception i raised
> in postgres so that i know the record doesnt exist?
You can use PHP's error handling capabilities to prevent errors
from being displayed automatically:
http://www.php.net/manual/en/ref.errorfunc.php
If you're sending queries with pg_query() then you can check its
return value to see if a query failed; if it did, you can call
pg_last_error() to get the error message.
http://www.php.net/manual/en/function.pg-query.php
http://www.php.net/manual/en/function.pg-last-error.php
If you're using other functions to interface with PostgreSQL then
see the documentation for those functions.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
From | Date | Subject | |
---|---|---|---|
Next Message | Walker, Jed S | 2005-04-13 15:30:09 | Serial data type |
Previous Message | sqlpython | 2005-04-13 15:03:44 |