Database Abstraction Layer for PHP

User Tools

Site Tools


Creating A New Driver

The simplest way to extend ADOdb for your own use is to create a new driver. ADOdb behaves like all PHP class definitions, in that its class methods and variables can be extended. As an example, we can look at the ADOdb driver /drivers/

This driver was created because the behaviour of Microsoft SQL Server 2012 differs slightly from previous versions when connecting via an ODBC connection.

The driver, in it's entirety, looks like this:

*  Microsoft SQL Server 2012 via ODBC
if (!defined('ADODB_DIR')) 
class  ADODB_odbc_mssql2012 extends ADODB_odbc_mssql
	* Makes behavior similar to prior versions of SQL Server
	var $connectStmt = 'SET CONCAT_NULL_YIELDS_NULL ON';
class  ADORecordSet_odbc_mssql2012 extends ADORecordSet_odbc_mssql
  • Both the connection and recordset classes must be defined, even if they are not modified
  • The driver must be located in the ADODB_DIR directory. Take care that the driver is not lost when upgrading
  • No other action is required, simply enter the name of the new driver in the newAdoConnection() statement.

Understanding The Data Provider

Because ADOdb V5 is not truly Object Orientated, an extended driver does not necessarily extend the required parent. One might expect to see the following chain of code:

class ADOnewConnection
class mysql extends ADOnewConnection
class mysqli extends mysql

But if we look at the source code of the mysqli driver (drivers/ , we can see that the class is defined like this

class ADODB_mysqli extends ADOConnection {
	var $databaseType = 'mysqli';
	var $dataProvider = 'mysql';

So the class extends the connector, but much of the MySQL specific functionality is found in the provider (drivers/ The provider is effectively a parallel class. So if we wanted, for example, to create a new driver mydriver that did not directly extend an existing class, but shared much of the feature with say, the mssqlnative class, our code might look like:

class ADODB_mydriver extends ADOConnection {
	var $databaseType = 'mydriver';
	var $dataProvider = 'mssqlnative';

Base Level Classes

If we look at say, the mssqlnative class, (drivers/ we see the following:

class ADODB_mssqlnative extends ADOConnection {
	var $databaseType = 'mssqlnative';
	var $dataProvider = 'mssqlnative';

In this case, the $databaseType and the $dataProvider are the same. This means that all of the functionality of the driver is provided by the named driver (drivers/ and datadict (datadict/ files .

Using Provider Classes

Data Provider classes are designed exactly the same as database driver classes. Where the provider class is different from the database class, the provider class is generally associated with an obsolete database version, often 15-20 years old. As such, they cannot be used as drivers.

v5/userguide/learn_extensions/new_driver.txt · Last modified: 2020/01/15 04:13 by mnewnham