ADOdb - database abstraction library for PHP
January 5th, 2006
ADOdb is what really saved my life when moving from Classic ASP to PHP5, it supports a wide variety of database, and has some great functionality features. It supports PHP5 aswell :)
You can find ADOdb here: http://adodb.sourceforge.net/
Here are some examples of your daily database connect and retrieval:
$DB = NewADOConnection(‘mysql’);
$DB->Connect($server, $user, $pwd, $db);
# M’soft style data retrieval with binds
$rs = $DB->Execute(“select * from table where key=?”,array($key));
while (!$rs->EOF) {
print_r($rs->fields);
$rs->MoveNext();
}
# PEAR style data retrieval
$rs = $DB->Execute(“select * from table where key=123″);
while ($array = $rs->FetchRow()) {
print_r($array);
}
# Alternative URI connection syntax:
$DB = NewADOConnection(“mysql://$user:$pwd@$server/$db?persist”);
# No need for Connect or PConnect when using URI syntax
$ok = $DB->Execute(“update atable set aval = 0″);
if (!$ok) mylogerr($DB->ErrorMsg());
Here is some more cool things you could do with ADOdb:
$ok = $DB->Execute(“update table set col1=? where key=?”,array($colval, $key));
# retrieving data shortcuts
$val = $DB->GetOne(“select col from table where key=’John’”);
$row = $DB->GetRow(“select col from table where key=’John’”);
$arr = $DB->GetAll(“select col from table”);
$arr = $DB->GetAssoc(“select key,col from table”); # returns associative array $key=>col
# Retrieve high speed cached recordsets (cached for 3600 secs)
# Cache directory defined in global $ADODB_CACHE_DIR.
# CacheGetOne, CacheRow, CacheGetAll all work
$rs = $DB->CacheExecute(3600, “select orgname from users where user=’JOHN’”);

2 comments on “ADOdb - database abstraction library for PHP”
01
I just switched over to ADODB from my own abstraction library. It’s amazing and I love the query caching feature, especially since MySQL’s own query caching doesn’t work.
02
I actually have trouble working out the cache on my Linux production server. Everything works fine on the Windows development computer, when I try it “live” on the server, I get a blank page on FF/IE. Wierd.