Table of Contents
Using Version 6 Connections
Introduction
Version 6 standardizes the way that connections are made to the database, and feature, either standard or driver-specific (OEM) is defined.
The Connection Definitions Class
Location
ADOdb\ADOConnectionDefinitions.php
In its simplest state, this is the only class necessary to establish a database connection and configure the way that ADOdb behaves. Features that were previously defined as either Global variables or constants are held in this file. As shown below, all available configuration items are exposed and can be modified before the database connection is made.
final class ADOConnectionDefinitions { /* * Value must be one of the supported V6 options */ public string $driver; /* * Defines the debugging level */ public int $debug = 0; /* * Defines the fetch mode - see ADODB_FETCH_MODE */ public int $fetchMode = 0; /* * Defines the record insertion force mode - ADODB_FORCE_TYPE */ public int $forceType = 3; /* * Defines the casing of associative arrays - see ADODB_ASSOC_CASE */ public int $assocCase = 0; /* * Defines the metatype for unknown types */ public string $defaultMetaType = 'N'; /* * Defines the ActualType for unknown types */ public string $defaultActualType = 'VARCHAR'; /* * Defines the connection parameters. If left false, * pass to connect(). Else use an array that signifies * connection, eg [database] [user] [password] */ public ?object $connection = null; /* * Set this to skip various driver loaded and valid tests */ public bool $assumeValidDriver = false; /* * Defines how getOne EOF is presented - see ADODB_GETONE_EOF */ public $getOneEOF = false; /* * Signifies if we want to count records - see COUNTRECS */ public bool $countRecords = true; /* * The language set to use for errors. defaults to US English */ public string $language = 'enUS'; /* * Quotes field names on update statements - see ADODB_QUOTE_FIELDNAMES * options - null, UPPER,LOWER,NATIVE */ public ?string $quoteFieldNames = null; /* * Tells the driver to auto-activate the transaction handling feature */ /* * Attaches the monolog stream handler */ public ?array $streamHandler = null; /* * Parameters that are executed with the oem connect, * if supported. Must be defined as 'driver'=>ADOOemFlags Class */ public array $oemFlags = array(); /* * 2d binding must be deliberately activated here * if you want to use it */ public bool $bulkBind = false; /* * If using Paging, set false to make the page count limitless */ public bool $pageExecuteCountRows = true; /* * Placeholders */ public ?object $loggingDefinitions = null; public ?object $dateTimeDefinitions = null; }
So to use it, the following action is required:
/* * Instantiate a copy of the class */ $acd = new ADOdb\ADOConnectionDefinitions; /* * Set the driver we want to use */ $acd->driver = 'mysqli'; /* * Set some value */ $acd->fetchMode = 2; //ADODB_FETCH_ASSOC /* * Push the definitions into the connection object */ $obj = new ADOdb\connector($acd);
The OEM Flags Class
ADOdb\database\drivers\<driver>\ADOOemFlags.php
Each driver has class that holds the driver specific options that can be used with ADOdb. The example below relates to the mysqli driver.
final class ADOOemFlags { /* * Allows an SSL Based connection */ public $ssl = array( 'ssl_key'=>null, 'ssl_cert'=>null, 'ssl_ca' => null, 'ssl_capath' => null, 'ssl_cipher' => null ); /* * Change the port number */ public int $port = 3306; /* * Change the socket */ public $socket = null; /* * For real_connect flags, e.g. MYSQLI_CLIENT_COMPRESS */ public int $flags = 0; /* * mysqli_option settings, e.g. MYSQLI_SERVER_PUBLIC_KEY * use Key=>Value */ public array $options = array(MYSQLI_READ_DEFAULT_GROUP=>0); /* * Enable multiquery. beware of sql injections */ public bool $multiQuery = false; }
So to use it, we must instantiate a copy of the ADOOemFlags class, modify it and push it into the ADOConnectionDefinitions class before the connection is started
$oemFlags = new ADOdb\Database\Drivers\mysqli\ADOOemFlags; /* * Change the port. for example */ $oemFlags->port = 13306; /* * Instantiate a copy of the class */ $acd = new ADOdb\ADOConnectionDefinitions; /* * Set the driver we want to use */ $acd->driver = 'mysqli'; /* * Push the OEM Flags into the class, keyed by driver */ $acd->oemFlags['mysqli'] = $oemFlags; /* * Push the definitions into the connection object */ $obj = new ADOdb\connector($acd);
