ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:userguide:learn_extensions:new_driver

This is an old revision of the document!


Building Extensions

You might want to modify ADOdb for your own purposes. Luckily you can still maintain backward compatibility by sub-classing ADOdb and using the $ADODB_NEWCONNECTION variable. $ADODB_NEWCONNECTION allows you to override the behaviour of ADONewConnection(). ADOConnection() checks for this variable and will call the function-name stored in this variable if it is defined.

In the following example, new functionality for the connection object is placed in the _hack_mysql_ and _hack_postgres7_ classes. The recordset class naming convention can be controlled using $rsPrefix. Here we set it to 'hack_rs_', which will make ADOdb use _hack_rs_mysql_ and _hack_rs_postgres7_ as the recordset classes.

class hack_mysql extends adodb_mysql {  
 
var $rsPrefix = 'hack_rs_';  
 
  /* Your mods here */  
 
}  
 
class hack_rs_mysql extends ADORecordSet_mysql {  
 
 /* Your mods here */  
 
}  
 
class hack_postgres7 extends adodb_postgres7 {  
 
var $rsPrefix = 'hack_rs_';  
 
  /* Your mods here */  
 
}  
 
class hack_rs_postgres7 extends ADORecordSet_postgres7 {  
 
 /* Your mods here */  
 
}  
 
$ADODB_NEWCONNECTION = 'hack_factory';  
 
function& hack_factory($driver)  
 
{  
 
         if ($driver !== 'mysql' && $driver !== 'postgres7') return false;  
 
           
 
         $driver = 'hack_'.$driver;  
 
         $obj = new $driver();  
 
         return $obj;  
 
}  
 
include_once('adodb.inc.php');
v5/userguide/learn_extensions/new_driver.1437238372.txt.gz · Last modified: 2017/04/21 11:40 (external edit)