Re: PEAR and MDB error management
| From: | Justin Patrin | Date: | Fri, 20 Aug 2004 17:06:24 +0000 |
| Subject: | Re: PEAR and MDB error management | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-14199@lists.php.net to get a copy of this message | ||
On Fri, 20 Aug 2004 11:45:54 +0200, Vincent DUPONT
<vincent.dupont@ausy.be> wrote:
> Ji,
>
> I would like to test if MDB can connect to a database. If my dsn is not correct, then
> MDB::connect returns an error I can trap with MDB::isError, and display the message. However, the
> error is then passed to the main errorHandliung fonction as define in my page as:
> PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "handleError");
>
> My test connection script is rather simple :
> $tmp_conn = & MDB::connect($dsn, $_SESSION['mdb_options']);
>
> if(MDB::isError($tmp_conn)){
>
> //display error message
>
> }
>
> else{
>
> //display Ok message
>
> $tmp_conn->disconnect();
>
> }
>
> I tried to change this script with :
>
> $this->expectError(MDB_ERROR_CONNECT_FAILED);
>
> $tmp_conn = & MDB::connect($dsn, $_SESSION['mdb_options']);
>
> $this->popExpect();
>
> if(!$tmp_conn){
>
> display error message
>
> }
>
> But this does not prevent the error to be passed back to the main error handling function of my
> script.
>
> Can anyone help me or point me to a good tutorial.
>
You've set the error mode to CALLBACK, so all errors will be sent to
the callback. If you don't want an error to be sent to the callback
(i.e. returned instead) you should change the error handling before
the call. IMHO setting the expect is only for errors you know you
don't have to handle. Try:
PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
$tmp_conn = & MDB::connect($dsn, $_SESSION['mdb_options']);
PEAR::popErrorHandling();
if (PEAR::isError($tmp_conn)) {
display error message
}
--
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder
paperCrane --Justin Patrin--