Jump to content

Tutorial on ADODB (PHP Database Manipulation Library)


Recommended Posts

For people who do not know about ADODB:ADODB is an object orientated database manipulation library for PHP, compatible with all major database server types, where you do not need to remember some functions for MySQL and others for Oracle, and you can make your scripts compatible with any database system.This PHP script:

<?php$con=mysql_connect('localhost', 'user', 'pass');mysql_select_db('mydb', $con);mysql_query('SELECT * FROM mytable');$con2=mssql_connect('localhost', 'user', 'pass');mssql_select_db('mydb', $con);mssql_query('SELECT * FROM mytable');?>

is exactly equal to this ADODB 5 script:

<?phpinclude ('adodb5/adodb.inc.php');$db=ADONewConnection('mysql');$db->Connect('localhost', 'user', 'pass', 'mydb');$db->Execute('SELECT * FROM mytable');$db2=ADONewConnection('mssql');$db2->Connect('localhost', 'user', 'pass', 'mydb');$db2->Execute('SELECT * FROM mytable');?>

As you can see, in the first script, you need to change the entire code, however in the second it is enough to change the database type of the ADODB object, which you can store in a remote config file.Now many sites use ADODB 5 for compability with other database systems and also for the ability to execute queries on different databases without destroying the connection and reconnecting.I think a tutorial about this on W3Schools would be of great use.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...