v5:activerecord:setdatabaseadapter
setDatabaseAdapter
See Also
Syntax
bool ADODB_Active_Record::setDatabaseAdapter( resource $database, optional string $label='' )
Description
This 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'); $db->connect(...); $ADOdb_Active_Record::setDatabaseAdapter($db);
Example, multiple connections
$db = NewADOConnection('mysqli'); $db2 = NewADOConnection('oci8'); $db->connect(...); $db2->connect(...); 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 = 'oConnection'; }
v5/activerecord/setdatabaseadapter.txt · Last modified: 2022/06/09 18:15 by dregad