Database abstraction Layer MDB2
As part of pear MDB2 is quite easy to get
pear install MDB2
pear install MDB2_Driver_$db
Usage is quite straigtforward too:
<?php
$dburl = “mysql://user:password@localhost/databaseName”;
require_once(“MDB2.php”);
$dbconnection = MDB2::factory($dburl);
$sql = “select * from users”;
$resultset = $dbconnection->query($sql);
if(PEAR::isError($resultset)) {
die(‘Failed to issue query, error message : ‘ . $resultset->getMessage());
}
while($row = $resultset->fetchRow(MDB2_FETCHMODE_ASSOC)) {
foreach($row as $field => $value) {
echo “$field / $value “;
}
}
/*************************************
* prepared statements are not to difficult
*************************************/
$sql = “UPDATE table SET column = ? WHERE id = ?”;
$types = array(‘integer’, ‘text’);
$statement = $con->prepare($sql, $types, MDB2_PREPARE_MANIP);
$data = array(5, ‘blah’);
$affected_rows = $statment->execute($data);
if(PEAR::isError($affected_rows)) {
// die etc.
}
?>