![[image]](http://mowser.com/img?url=http%3A%2F%2Fadodb.sourceforge.net%2Fadodb.gif)
Download Documentation Forums (post bug reports here) Changelog FAQ
ADOdb is a database abstraction library for PHP. There is also a Python version; see the ADOdb for Python docs.
The PHP version currently supports an amazing number of databases, thanks to the wonderful ADOdb community: MySQL, PostgreSQL, Interbase, Firebird, Informix, Oracle, MS SQL, Foxpro, Access, ADO, Sybase, FrontBase, DB2, SAP DB, SQLite, Netezza, LDAP, andgeneric ODBC, ODBTP. The Sybase, Informix, FrontBase and PostgreSQL, Netezza, LDAP, ODBTP drivers are community contributions. Here is the complete list of drivers.
Many popular web applications such as ACID, Zikula/PostNuke, Xaraya, phpWiki, Mambo, PHP GACL, TikiWiki, eGroupWare and phpLens App Server are using ADOdb as their database abstraction layer. Some reasons why ADOdb is popular include:
include('/path/to/adodb.inc.php');
$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());
Other things you can try include:
# Updating tables
$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'");
And there are more connection examples showing you how to connect to SQLite, Oracle, PostgreSQL, Microsoft SQL Server, MS Access, LDAP, Interbase/Firebird etc.
$rs = $DB->Execute("select * from table");
foreach ($rs as $row) {
print_r($row);
}
If you include the following adodb-exceptions.inc.php file, then ADOdb will throw exceptions when an error occurs:
include("/path/to/adodb-exceptions.inc.php");
include("/path/to/adodb.inc.php");
$DB = NewADOConnection('oci8');
$DB->Connect("", "scott", "tiger");
try {
$DB->Execute("select badsql from badtable");
} catch (exception $e) {
print_r($e);
}
Requirements: PHP 5.0 or later. There is a version available that works with PHP 4.1 to 5.2 also.
Installation: Unpack files into a directory. Try the above sample code, adjusting the connection parameters to suit your database server, and modify the sql to match your tables.
Debugging: Set your connection's debug property, e.g. $DB->debug=true; if you are having problems. It will output lots of useful status and error messages.
ADOdb Lite is a separate PHP project done by a 3rd party to cut down the ADOdb library to use a smaller footprint.
Download from SourceForge Python ADOdb Docs
Data Dictionary for schema creation.
Performance Monitoring.
Database-backed Session Management.
MySQL Tutorial
Advanced Oracle Tutorial
Portable SQL Tips with ADOdb
ADOdb Active Record, an OOP encapsulation of a database record.
DevShed has some excellent articles by icarus about ADOdb. Latest version of articles at MelonFire:
Part 1 on Basics and Part 2 on Advanced ADOdb. Original articles at DevShed.
We have PHP documentation in other languages:
and tutorials in:
For bug reports, feature requests and questions, use the ADOdb Forums. The author monitors this forum.
You are viewing a mobilized version of this site...
View original page here