Re: Pear_Error not triggered when mysql is down with MDB2
| From: | Justin Patrin | Date: | Fri, 08 Jul 2005 02:34:33 +0000 |
| Subject: | Re: Pear_Error not triggered when mysql is down with MDB2 | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-19903@lists.php.net to get a copy of this message | ||
On 7/7/05, Dan Rossi <pear@electroteque.org> wrote:
>
> 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.
>
I understand this, but the question you should be asking here is why
the error isn't being sent to your callback. Please check the error
returned and see what it says. Then try to figure out which raiseError
call is sending it back. Then trace the calls to figure out why the
callback isn't being called.
Also, check for any expectError or pushErrorHandler calls, which would
stop the callback.
--
Justin Patrin