Re: Pear_Error not triggered when mysql is down with MDB2
| From: | Dan Rossi | Date: | Fri, 08 Jul 2005 01:04:46 +0000 |
| Subject: | Re: Pear_Error not triggered when mysql is down with MDB2 | ||
| References: | 1 2 3 4 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-19901@lists.php.net to get a copy of this message | ||
On 08/07/2005, at 5:31 AM, Lorenzo Alberton wrote:
of course it is... if it can't connect, it returns a MDB2_Error (which is a subclass of PEAR_Error) as it should, and which you have to check for. The dbms error is mapped into a PEAR_Error for consistency. Your error message says: Fatal error: Call to undefined method MDB2_Error::setFetchMode() in $this->_db = MDB2::connect(); that means that $this->_db is a MDB2_Error object (returned by MDB2::connect()), and that there is no such method as setFetchMode() in the MDB2_Error class. You missed the error check between the connect() and setFetchMode() calls.Lets go into it for a sec if (!isset($dsninfo['phptype'])) {
return MDB2::raiseError(MDB2_ERROR_NOT_FOUND,
null, null, 'no RDBMS driver specified');
}
Within the connect method, this triggers the pear callback error class.
Within the connect method of the db driver
$connect_function = $this->options['persistent'] ? 'mysql_pconnect' : 'mysql_connect';
@ini_set('track_errors', true);
$php_errormsg = '';
$connection = @call_user_func_array($connect_function, $params);
@ini_restore('track_errors');
if (!$connection) {
if (($err = @mysql_error()) != '') {
return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, $err);
} else {
return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, $php_errormsg);
}
}
Which raiseError is being called in the driver common class. Theoretically it should trigger MDB2::raiseError which in turn triggers
function &raiseError($code = null, $mode = null, $options = null, $userinfo = null)
{
return PEAR::raiseError(null, $code, $mode, $options, $userinfo, 'MDB2_Error', true);
}
Seems to work for everything
except this line which is obviouslly returning the error
if (!$connection) {
if (($err = @mysql_error()) != '') {
return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, $err);
} else {
return $this->raiseError(MDB2_ERROR_CONNECT_FAILED, null, null, $php_errormsg);
}
}
Now for being descriptive here is how i setup the callback
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(&$errors, 'errorStack'));
Now I prefer callbacks than handling the errors in the hundreds of classes and scripts i do, its all handled in the one spot.