db asbstraction
| From: | Colin Viebrock | Date: | Thu, 25 Jan 2001 19:47:20 +0000 |
| Subject: | db asbstraction | ||
| Groups: | php.pear | ||
| Request: | Send a blank email to php-pear+get-1171@lists.php.net to get a copy of this message | ||
Okay, I'm trying to grok this DB abstraction thing, and convert scripts
that use my own homemade abstraction to PEAR.
Here is my old code, and it's PEAR equivalent:
# my way
$DB = new DB();
$DB->connect($host,$db,$user,$pass);
$DB->query("SELECT name FROM table");
if ($DB->numrows()>0) {
while ($DB->fetchRow()) {
echo $DB->field('name');
}
}
$DB->freeResult();
# PEAR's way
$DB = DB::connect($dsn);
$result = $DB->query("SELECT name FROM table");
if ($result->numRows()>0) {
while ($row = $result->fetchRow()) {
echo $row['name'];
}
}
Now, PEAR's code isn't any bigger or necessarily more confusing. But I
need to use separate variables for $DB, $result and $row, as compared to
my class which makes all of this information available through $DB.
I'm just wondering if I'm missing something, or if this is indeed how
PEAR was meant to work.
--
Colin Viebrock
Co-Founder, easyDNS Technologies
http://www.easyDNS.com/