ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:activerecord:setdatabaseadapter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
activerecord:setdatabaseadaptor [2015/12/06 02:01] mnewnhamv5:activerecord:setdatabaseadapter [2022/06/09 18:15] (current) – ↷ Page name changed from v5:activerecord:setdatabaseadaptor to v5:activerecord:setdatabaseadapter dregad
Line 1: Line 1:
-====== setDatabaseAdaptor ======+====== setDatabaseAdapter ======
 ~~NOTOC~~ ~~NOTOC~~
 <WRAP right box> <WRAP right box>
 +== See Also ==
 +[[v5:activerecord:dbat|$_dbat Class Variable]]
 == Syntax == == Syntax ==
    bool ADODB_Active_Record::setDatabaseAdapter(    bool ADODB_Active_Record::setDatabaseAdapter(
-       resource $database+       resource $database
 +       optional string $label=''
    )    )
 </WRAP> </WRAP>
 ===== Description ===== ===== 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.+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 ===== ===== Usage =====
 +Example, using single connection
 <code php> <code php>
-$db = NewADOConnection(...); +$db = newAdoConnection('mysqli'); 
-$db2 = NewADOConnection(...);+$db->connect(...); 
 +$ADOdb_Active_Record::setDatabaseAdapter($db); 
 +</code> 
 +Example, multiple connections 
 +<code php> 
 +$db  = NewADOConnection('mysqli'); 
 +$db2 = NewADOConnection('oci8');
  
-ADOdb_Active_Record::SetDatabaseAdapter($db2);+$db->connect(...); 
 +$db2->connect(...);
  
-$activeRecs = $db->GetActiveRecords('table1');+ADOdb_Active_Record::SetDatabaseAdapter($db,'mConnection'); 
 +ADOdb_Active_Record::SetDatabaseAdapter($db2,'oConnection');
  
-foreach($activeRecs as $rec) +class mPerson extends ADODB_Active_Record
 { {
-   $rec2 new ADOdb_Active_Record('table2',$db2); +    /* 
-   $rec2->id = $rec->id; +    * Assigns the mysql connection to this class 
-   $rec2->name = $rec->name; +    */  
-   $rec2->Save();+    public $_dbat = 'mConnection';
 } }
 +
 +class oPerson extends ADODB_Active_Record
 +{
 +    /*
 +    * Assigns the oracle connection to this class
 +    */ 
 +    public $_dbat = 'oConnection';
 +}
 +
 +
 </code> </code>
v5/activerecord/setdatabaseadapter.1449363672.txt.gz · Last modified: 2017/04/21 11:21 (external edit)