ADOdb Database Abstraction Library for PHP (and Python)

2012 年 9 月 29 日8110

ADOdb Database Abstraction Library for PHP (and Python)

(c) 2000-2011 John Lim
(jlim#natsoft.com). All rights reserved.

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,
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, 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:

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 license.txt in your release. Also
dual-licensed (Lesser GPL).

PHP Code Samples

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 ,
,
,
Microsoft
SQL Server, MS
Access, ,

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) {
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);
}

PHP Download

Download
from SourceForge

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

ADOdb Lite is a separate PHP project done by a 3rd party to cut down the ADOdb library to use a smaller footprint.

Python Downloads

Requires Python 2.3 or later. Works fine with Psyco.

Download
from SourceForge
Python
ADOdb Docs

Speed Up Your PHP Code with the ADOdb extension

Adodb-ext-504.zip
provides up to 100% speedup by replacing parts of ADOdb with C code.
ADOdb will auto-detect if this extension is installed and use it
automatically. This extension is compatible with ADOdb 3.32 or later,
and PHP 4.3 - 5.x.x. Source code is included. Please note that you will need to compile it yourself. Instructions included.

PHP Documentation

One HTML
Page (this is always the most up-to-date)
Multiple HTML Pages
Windows CHM
Format

Python
ADOdb Docs

Other Docs for PHP version

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.

Translations

We have PHP documentation in other languages:

Korean
Spanish (Castellano)
Japanese

and tutorials in:

Chinese

Francais

German

Italian

Polish

Russian
Spanish (Castellano)
Thai

Mailing Lists

For bug reports, feature requests and questions, use the ADOdb Forums.
The
author monitors this forum.


(c) 2000-2008 John Lim. All Rights Reserved. Contact: jlim#natsoft.com

0 0