- skip to content

# Database Abstraction Layer

### User Tools

- Login

### Site Tools

- Recent changes
- Media Manager
- Sitemap

### Sidebar

##### Resources

- Reference Manual
- User Guide
- The Data Dictionary
- ADOdb-xmlschema
- ADOdb Active Record
- Performance Monitoring
- Date/Time Library
- Session Management Library
- Unsupported Addons
- Coding Standards

##### Supported Databases

- Access
- ADO
- CSV
- Firebird
- Frontbase
- IBM DB2
- Informix
- Interbase
- LDAP
- Microsoft SQL Server
- MySQL
- Netezza
- ODBC
- ODBTP
- Oracle
- PDO
- Postgresql
- SAP ADS
- SAP ASE
- SAP Maxdb
- SAP Sqlanywhere
- Sqlite
- Sybase
- Plain Text
- Visual Foxpro

##### Other

- Feature Comparison Matrix
- Connection Matrix
- Include File Guide

v5:activerecord:setdatabaseadaptor

# setDatabaseAdaptor

##### See Also

$_dbat Class Variable

##### 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::setDatabaseAdaptor($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/setdatabaseadaptor.txt · Last modified: 2016/01/12 17:15 by mnewnham

### Page Tools

- Show pagesource
- Old revisions
- Backlinks
- Rename Page
- Back to top