Re: PEAR DB examples?

From: Date: Fri, 08 Sep 2000 14:15:21 +0000
Subject: Re: PEAR DB examples?
References: 1 2 3  Groups: php.pear 
Request: Send a blank email to php-pear+get-238@lists.php.net to get a copy of this message
> On Fri, 08 Sep 2000, Stig Bakken wrote: > > I usually approach this in one of three ways depending on what the > > application needs: > > [snip] > > Stig, > > Thanks for sharing the implementation examples. Currently, I use a class > based on PHPLIB's database class with some custom additions. Sometimes, > there is a need for more than one database object to be active, like if > I'm processing one set of items and each item requires another query. > Example: > > $sql = new SQL; > $sql2 = new SQL; > $sql->query("select article_id from articles where author_id = 1"); > while ($sql->next()) { > $sql2->query("select image_id from images where article_id = ". > $sql->record['article_id']); > ... > } > <?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]); //... } ?>

« previous php.pear (#238) next »