ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:activerecord:setdatabaseadapter

This is an old revision of the document!


setDatabaseAdaptor

Syntax
 bool ADODB_Active_Record::setDatabaseAdapter(
     resource $database,
     optional string $label=''
 )

Description

This allows links the Active Record class to an ADOdb database connection. The method returns true if it is a valid connection, or false if not. The optional $label parameter allows multiple database connections to be assigned to the same ADODB_Active_Record class. Note that even though multiple connections can be attached to the base class, only one can be used, so the class must be extended to use the connections


Usage

Example, using single connection

$db = newAdoConnection('mysqli');
$ADOdb_Active_Record::setDatabaseAdaptor($db);

Example, multiple connections

$db  = NewADOConnection('mysqli');
$db2 = NewADOConnection('oci8');
 
ADOdb_Active_Record::SetDatabaseAdapter($db,'mConnection');
ADOdb_Active_Record::SetDatabaseAdapter($db2,'oConnection');
 
class mPerson extends ADODB_Active_Record
{
    /*
    * Assigns the mysql connection to this class
    */ 
    public $_dbat = 'mConnection';
}
 
class oPerson extends ADODB_Active_Record
{
    /*
    * Assigns the oracle connection to this class
    */ 
    public $_dbat = 'moonnection';
}
v5/activerecord/setdatabaseadapter.1449366451.txt.gz · Last modified: 2017/04/21 11:21 (external edit)