Re: Pear DB Tutorial
| From: | (Stig Sæther Bakken) | Date: | Tue, 17 Apr 2001 01:51:45 +0000 |
| Subject: | Re: Pear DB Tutorial | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-243@lists.php.net to get a copy of this message | ||
["Tomas V.V.Cox" <cox@idecnet.com>]
>
> Before setErrorHandling you have to check if $dbh is not an error. If it
> is an error you don't have setErrorHandle and if it isn't you don't need
> it :)
>
> $dbh = DB::connect($dsn);
> if (DB::isError($dbh)) {
> handle_error ($dbh);
> }
Okay, I just fixed DB.php so it uses raiseError, then it too uses the
"global default" error handler like this:
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "handle_error");
$dbh = DB::connect($dsn);
Now, if an object uses $this->raiseError("foo") and no defaults are
set for the object (with $obj->setErrorHandling(), the global default
error handling applies.
> Perhaps your example works better with results objects:
>
> $res = $dbh->query($sql);
> if (DB::isError($res)) {
> handle_error ($res);
> } else {
> $res->setErrorHandling(PEAR_ERROR_CALLBACK, "handle_error");
> ...
> }
>
> But there is still to much code to write (the matter of this thread).
> Perhaps if we propagate the error handling mode throw the new results
> objects can work better. Any way, me, my self and I prefer the way I
> originally post ;)
So now all the code you have to write is this:
PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, "handle_error");
$dbh = DB::connect($dsn);
$res = $dbh->query($sql);
Done. The default default error handler takes care of the rest. No
need to develop repetitive strain injuries just to deal with errors. :-)
> >
> > The same method can be used for any class that inherits PEAR. It
> > appears some more documentation (and maybe some evangelism?) would
> > help? :-)
>
> Hey your are our prophet! :) In the next days I'll try to extend the
> Tutorial.
Great.
- Stig
--
Stig Sæther Bakken <ssb@fast.no>
Fast Search & Transfer ASA, Trondheim, Norway