ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v6:connector

This is an old revision of the document!


Building A Connection

Overview

This section describes the method of setting up a connection to the database and activate all the appropriate modules.

Database Connector

Prerequisites

  • The Logging class **monolog**. ADOdb requires 2 channels available, DEBUG for all debug logging options, and CRITICAL for recording database errors.
  • A PSR-Compliant autoloading mechanism

Description

A connection is made using the connection class** ADOdb\connector **

The default connection is set up by defining a set of parameters associated with the database connection. The definitions required for connection are contained in 2 classes.

  1. The ADOConnectionDefinitions contains all the common connection definitions. This is standardised for all databases types.
  2. The ADOOemFlags class contains database specific entries. These entries vary from database to database. A default connection to the database can be made without setting OEM Flags. To see available flags, see the manual entry for each driver.

To create the connection, follow these steps


** ADOdb\database\drivers\<driver>\ADOOemFlags **

1. Set Driver Specific Flags

This step is optional. If you are going to use a driver specific option, for example overriding the default prefetch rows in the oci8 driver, or change the connection port from 3306 in the mysqli driver, do that here.

Example

use ADOdb\database\drivers\mysqli;
 
$oemFlags = new ADOdb\database\drivers\mysqli\ADOOemFlags;
 
$oemFlags->port = 23306;

2. Set up the Monolog Channels

This section is optional, but recommended. If you do not define streams for the monolog logging, then default streams will be created. These write text log data to the ADOdb directory.

Example

use Monolog\Logger;
use Monolog\Handler\StreamHandler;
 
 
$debugStreamHandler    = new StreamHandler('/logs/debug.log', Logger::DEBUG);
$criticalStreamHandler = new StreamHandler('/logs/critical.log', Logger::CRITICAL);

** ADOdb\time\ADODateTimeDefinitions **

3. Set Up The Date/Time Definitions

This section is optional. If you will be using the ADOdb date/time class in conjunction with the database connector and wish to change configuration points such the locale, do that here

Example

$dtd = new ADOdb\time\ADODateTimeDefinitions;
 
$dtd->locale = 'FR';

** ADOdb\cache\ADOCachingDefinitions **

4. Set Up The Caching Service

This section activates an optional feature. For configuration options, read the V6 Caching Service section


** ADOdb\ADOConnectionDefinitions **

5. Create A Definitions Class

This step is mandatory. The database type, which must be one of those supported by Version 6, will be added at this point. In addition, certain configuration parameters, such as the default Fetch Mode are also defined here. At the same time, the optional OEM flags, caching definitions and monolog definitions are added.

The database connection parameters can be optionally added at this point. For more information see the description connect()

Example

use ADOdb\database\drivers\mysqli;
 
$acd = new ADOdb\ADOConnectionDefinitions(
        $monologHandlers,
        $dateTimeDefinitons,
        $cachingDefinitions);
 
$acd->driver = 'mysqli';
 
$acd->fetchMode = $acd::ADODB_FETCH_ASSOC;

** ADOdb\connector **

6. Instantiate The Connector

This section establishes a connection to the database using the provided credentials.

Example

/*
* $acd is the ADOConnectionDefinitions Class defined above
*/
$connectionObject = new ADOdb\connector($acd);
 
/*
* Create the database connection
*/
$db = $connectionObject->connect($host,$user,$pass,$database);

There are multiple ways to provide the credentials. For more information see connect()


** ADOdb\session\ADOSessionDefinitions **

7. Add the session management connection

This section activates an optional feature. For configuration options, read the V6 Session Management section

Example

/*
* Establish the connection first
*/
$db = $connectionObject->connect($host,$user,$pass,$database);
 
 
$asd = new ADOdb\session\ADOSessionDefinitions;
 
$session = $obj->startSession($asd);
v6/connector.1600813635.txt.gz · Last modified: by 127.0.0.1