PHP Application Development With ADODB

ADODB is a powerful databaseabstraction library for PHP applications. As a developer, one of the most important things to consider when developing a Web application is portability. Given the rapid pace of change in the Web world, it doesn’t do to bind your code too tightly to a specific operating system, RDBMS or programming language; if you do, you’ll find yourself reinventing the wheel every time things change on you (and they will – take my word for it).

PHP’s database access functions are not standardised. This creates a need for a database class library to hide the differences between the different database API’s (encapsulate the differences) so we can easily switch databases. For example, When we use PHP database classes, if we want to execute select query to get data from mysql database, we need to use the mysql_query() function. If we want to execute the same query to get data from MS SQL server, we need to use the mssql_query() function. But the ADODB class library provides a commen function Execute() to execute the same select query in all supported databases($db->Execute(‘select * from tbl_category’)). The ADODB currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access, ADO and ODBC.

The Features of ADOdb

  • Unlike other PHP database classes which focus only on select statements, ADODB provide support code to handle inserts and updates which can be adapted to multiple databases quickly. Methods are provided for date handling, string concatenation and string quoting characters for differing databases.

  • A metatype system is built in so that we can figure out that types such as CHAR, TEXT and STRING are equivalent in different databases.
  • Easy to port because all the database dependant code are stored in stub functions. You do not need to port the core logic of the classes.
  • PHP4 session support.

Quick Installation Guide.

  1. Make sure you are running PHP 4.0.5 or later.
  2. Download the ADODb class library from here – Download ADODb
  3. Unpack all the files into a directory accessible by your webserver.
  4. Create a new datatbase. For this example, I am using mysql database,MySQL Workbench 5.2 and I have created a database called “ecards”. In that database, i am going to create a new table called “tbl_product”. The following is the SQL Query for my database table.

DROP TABLE IF EXISTS tbl_product ;
name VARCHAR(45) NULL ,
price DECIMAL(9,2) NULL ,
sort_description TEXT NULL ,
detail_description TEXT NULL ,
tbl_category_id INT NOT NULL ,
tbl_admin_id INT(11) NOT NULL ,

include(‘adodb/’); // this line will load the ADODb class library in tour application

$dbType = ‘mysql’;

$SERVER = ‘’; // or the host name, example – localhost

$USER = ‘root’; // the database username

$PASSWORD = ‘root’; // the database password

$DATABASE = ‘ecards’; // the database name

$db = ADONewConnection($DATABASE); // create a new database object

$db->debug = true; // set the debug true, so u can debug ur application

$db->Connect($server, $user, $password, $database); // make a connection with database server

$rs = $db->Execute(‘select * from tbl_product’); // select all the record from the tbl_product table

// and print the result on the browser

print “<pre>”;


print “</pre>”;

Now access the file from the brower, for example –, you will be able to see all the records from the tbl_product table

Be the first to comment

Leave a Reply

Your email address will not be published.