Re: PHPLib and Pear merge
| From: | Paul Meagher | Date: | Wed, 07 Mar 2001 13:31:58 +0000 |
| Subject: | Re: PHPLib and Pear merge | ||
| References: | 1 2 | Groups: | php.pear |
| Request: | Send a blank email to php-pear+get-1598@lists.php.net to get a copy of this message | ||
Upon hearing about the benchmarks I questioned whether I had made the right
decision to use the PEAR DB abstraction layer.
I decided to create a second parallel version of the code I was developing
so that it used PHPLIB's db_sql class for mysql.
What I discovered is that the port wasn't that difficult to do.
** First example:
The PHPLIB way:
function deleteCat($cat_id)
{
global $db;
$sql = "DELETE FROM $this->cat_table WHERE $this->cat_id='$cat_id'";
if ($db->query($sql)) {
return true;
} else {
return false;
}
}
The PEAR: DB way:
function deleteCat($cat_id)
{
global $db;
$sql = "DELETE FROM $this->cat_table WHERE $this->cat_id='$cat_id'";
$sth = $db->query($sql);
if (DB::isError($sth)) {
// print $sth->getMessage();
return false;
} else {
return true;
}
}
** Second example
PHPLIB way of dumping records
$db->query($sql);
while($db->next_record()) {
$cat_id = $db->f('cat_id');
$cat_pos = $db->f('cat_pos');
$cat_name = $db->f('cat_name');
PEAR way:
$sth = $dbh->query($sql);
while($row = $sth->fetchRow()) {
$cat_id = $row['cat_id'];
$cat_pos = $row['cat_pos'];
$cat_name = $row['cat_name'];
Ok, so I suppose they are a bit diff but I thought I would leave you with
some grist to consider whether it would make sense to make the API's
between PEAR:DB and DB_Sql sufficiently similiar that one would switch
abstraction layers with a simple a local.inc file (or whatever you want to
name your local subclassing file).
Regards,
Paul Meagher