Re: PEAR DB examples?

From: Date: Fri, 08 Sep 2000 14:25:39 +0000
Subject: Re: PEAR DB examples?
References: 1 2 3 4 5  Groups: php.pear 
Request: Send a blank email to php-pear+get-240@lists.php.net to get a copy of this message
> On Fri, 08 Sep 2000, Sterling Hughes wrote: > > <?php > > $dbh = DB::connect("mysql://user:pass@server/dbname"); > > > > if (DB::isError($dbh)) { > > die(sprintf("Error [%d]: %s", > > $dbh->getCode(), $dbh->getMessage())); > > } > > > > $sth1 = $dbh->query("select article_id from articles where author_id = 1"); > > > > // .. same error checks apply to queries > > > > while (is_array($row = $sth1->fetchRow())) { > > $sth2 = $dbh->query("select image_id from images where article_id = " . > > $row[article_id]); > > //... > > } > > ?> > > > > Hmm, I see. It might get a little annoying to write error checks after > each query - is there a way to automate that a bit? > > -Andrei > Perhaps we could have a register_error_function method: function error ($obj) { die(sprintf("Error [%d]: %s", $obj->getCode(), $obj->getMessage())); } $dbh->register_error_function("error"); // .. Normal stuff, the error function will be called on error. No need to check -Sterling

« previous php.pear (#240) next »