ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v6:connector

Differences

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

Link to this comparison view

v6:connector [2020/09/22 15:27] – created - external edit 127.0.0.1v6:connector [2026/08/31 12:19] (current) – removed mnewnham
Line 1: Line 1:
-====== 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 [[https://github.com/Seldaek/monolog|**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.  
- 
-  - The [[v6:reference:adoconnectiondefinitions|ADOConnectionDefinitions]]  contains all the **common** connection definitions. This is standardised for all databases types.  
-  - The [[v6:reference:adoconnectiondefinitions|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 
- 
--------------------------------- 
-<WRAP right box> 
-''** ADOdb\database\drivers\<driver>\ADOOemFlags **'' 
-</WRAP> 
-==== 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 === 
-<code php> 
- 
-use ADOdb\database\drivers\mysqli; 
- 
-$oemFlags = new ADOdb\database\drivers\mysqli\ADOOemFlags; 
- 
-$oemFlags->port = 23306; 
- 
-</code> 
-------------------------------------------------- 
-==== 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 === 
-<code php> 
- 
-use Monolog\Logger; 
-use Monolog\Handler\StreamHandler; 
- 
- 
-$debugStreamHandler    = new StreamHandler('/logs/debug.log', Logger::DEBUG); 
-$criticalStreamHandler = new StreamHandler('/logs/critical.log', Logger::CRITICAL); 
- 
-</code> 
----------------------------------------------- 
-<WRAP right box> 
-''** ADOdb\time\ADODateTimeDefinitions **'' 
-</WRAP> 
-==== 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 === 
-<code php> 
- 
-$dtd = new ADOdb\time\ADODateTimeDefinitions; 
- 
-$dtd->locale = 'FR'; 
-</code> 
----------------------------------------------- 
-<WRAP right box> 
-''** ADOdb\cache\ADOCachingDefinitions **'' 
-</WRAP> 
-==== 4. Set Up The Caching Service ==== 
-This section activates an **optional feature**. For configuration options, read the [[v6:caching]] section 
------------------------------------------------ 
-<WRAP right box> 
-''** ADOdb\ADOConnectionDefinitions **'' 
-</WRAP> 
-==== 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 [[v6:reference:connection:connect|connect()]] 
-  
-=== Example === 
-<code php> 
- 
-use ADOdb\database\drivers\mysqli; 
- 
-$acd = new ADOdb\ADOConnectionDefinitions( 
-        $monologHandlers, 
-        $dateTimeDefinitons, 
-        $cachingDefinitions); 
- 
-$acd->driver = 'mysqli'; 
- 
-$acd->fetchMode = $acd::ADODB_FETCH_ASSOC; 
- 
-</code> 
------------------------------------------------ 
-<WRAP right box> 
-''** ADOdb\connector **'' 
-</WRAP> 
-==== 6. Instantiate The Connector ==== 
-This section establishes a connection to the database using the provided credentials. 
-=== Example === 
-<code php> 
- 
-/* 
-* $acd is the ADOConnectionDefinitions Class defined above 
-*/ 
-$connectionObject = new ADOdb\connector($acd); 
- 
-/* 
-* Create the database connection 
-*/ 
-$db = $connectionObject->connect($host,$user,$pass,$database); 
-</code> 
- 
-There are multiple ways to provide the credentials. For more information see [[v6:reference:connection:connect|connect()]] 
------------------------------------------------------ 
-<WRAP right box> 
-''** ADOdb\session\ADOSessionDefinitions **'' 
-</WRAP> 
-==== 7. Add the session management connection ==== 
-This section activates an **optional feature**. For configuration options, read the [[v6:sessions]] section 
-=== Example === 
-<code php> 
- 
-/* 
-* Establish the connection first 
-*/ 
-$db = $connectionObject->connect($host,$user,$pass,$database); 
- 
- 
-$asd = new ADOdb\session\ADOSessionDefinitions; 
- 
-$session = $obj->startSession($asd); 
- 
-</code> 
  
v6/connector.1600813635.txt.gz · Last modified: by 127.0.0.1