ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:learn_extensions:extend_existing:modify_existing_driver

Extending An Existing Driver

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');

End Of Lesson 10

v5/learn_extensions/extend_existing/modify_existing_driver.txt · Last modified: 2016/03/19 01:39 by mnewnham