ADOdb Database Abstraction Library for PHP

v5.20.2 - 27-Dec-2015

Download   Source code   Documentation   Support   Changelog  FAQ

ADOdb is a database abstraction library for PHP

It 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, and generic 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, 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:

  • Designed for speed. It is probably the fastest open source database abstraction library available for PHP. See benchmarks.
  • Provides extensive portability support such as date and type-handling and portable schema creation. See portable sql tips
  • Support many enterprise features such as database backed sessions (with session expiry notification), SQL code generation, pivot tables, SELECT LIMIT emulation for all databases, performance monitoring.
  • Easy to learn, especially if you have Window's programming experience, as it uses many ADO conventions.
  • Extensive QA, every release is unit-tested on Access, MySQL, PostgreSQL, MS SQL, Oracle 11g.
  • Mature, continiously developed since August 2000. Has a large community of users.
  • Powerful Active Record support. See docs.
  • Very reasonable licensing terms (BSD). This means that you can incorporate (and even compile) it into your software applications royalty-free without asking the author's permission, provided you include the ADOdb Licence in your release. Also dual-licensed (Lesser GPL v2.1).

PHP Code Samples

$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.

PHP5 Support

ADOdb has full PHP5 support, including SPL and exception support. For example, you can do this in PHP5:
$rs = $DB->Execute("select * from table");
foreach ($rs as $row) {
If you include the following file, then ADOdb will throw exceptions when an error occurs:
$DB = NewADOConnection('oci8');
$DB->Connect("", "scott", "tiger");
try {
$DB->Execute("select badsql from badtable");
} catch (exception $e) {


Download from SourceForge

Requirements: PHP 5.0 or later.

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 Documentation

One HTML Page

Data Dictionary for schema creation.
Performance Monitoring.
Database-backed Session Management.

Other Docs for PHP version

The documents in this section are maintained (or not, as the case may be) by their respective authors and are therefore potentially out of date or even obsolete.

MySQL Tutorial
Advanced Oracle Tutorial
Portable SQL Tips with ADOdb
ADOdb Active Record, an OOP encapsulation of a database record.

A couple excellent articles by icarus about ADOdb at MelonFire:

    Part 1 on Basics and Part 2 on Advanced ADOdb.


PHP documentation in other languages:

and tutorials in:


Bug reports, feature requests and questions should be filed on Github.

To discuss with the ADOdb development team and users, connect to our Gitter chatroom using your Github credentials.
Join chat on Gitter

The legacy ADOdb forums are still available in read-only mode for reference.

© 2000-2013 John Lim (
© 2014 Damien Regad, Mark Newnham and the ADOdb community