PDO (new)
This is still under development. Feedback is welcome, just add your comments in the pull request.
Specification
Driver Name | pdo |
---|---|
Data Provider | pdo |
Status | Active1) |
Windows | Yes |
Unix | Yes |
ADOdb V5 | Yes |
ADOdb V6 | Yes |
Description
This driver supports connections using the standardized PHP Data Objects.This page refers to ADOdb release 5.23.0 and higher. For previous versions of ADOdb, see the Previous Version Of This Page.
Except for the pdo_odbc
driver, all PDO drivers include support for full data dictionary functions (e.g. createTableSql()
,addIndexSql()
, etc.)
Quick Upgrade Notes
- Instead of
newAdoConnection('pdo')
, usenewAdoConnection('pdo\driver')
- Passing a DSN statement to
newAdoConnection()
is no longer supported - Do not start the DSN statement with the driver name
Supported drivers
PHP Driver | Description | ADOdb Connector |
---|---|---|
pdo_firebird | Firebird | firebird |
pdo_ibm | IBM DB2 | ibm |
pdo_informix | IBM Informix | informix |
pdo_mysql | MySQL | mysql |
pdo_oci | Oracle | oci |
pdo_odbc | Generic ODBC | odbc |
pdo_pgsql | Postgresql | pgsql |
pdo_sqlite | SQLite | sqlite |
pdo_sqlsrv | Microsoft SQL Server | sqlsrv |
Unsupported Drivers
- pdo_mssql
- pdo_dblib
- pdo_cubrid
Note that the pdo driver cannot be used on its own. It is a technical component that is used internally by the above drivers.
Establishing A Connection
To establish a connection:
- The PDO database type must be specified in the
ADONewConnection()
function call - The DSN style of connection must be used in the
connect()
statement, e.g. to connect to a MySQL database:
include_once 'adodb/adodb.inc.php'; $db = ADOnewConnection('pdo\mysql'); $user = 'pdo-user'; $password = 'pdo-pass'; $dsnString= 'host=localhost;dbname=employees;charset=utf8mb4'; $db->connect($dsnString,$user,$password);
Preferred Drivers
Using ADOdb effectively eliminates the need to use the PHP PDO driver as it hides the PHP level command:
- It provides true database abstraction, for example, the ADOdb method
selectLimit()
provides a true abstraction of the row limiting and offset of all databases. With PDO, you still need to provide the database specific syntax. - Unless otherwise described below, using native drivers (listed below) provide better functionality, as well as performance, than the equivalent PDO driver. This is true at both the ADOdb and PHP level
Setting Construction Parameters
Certain attributes need to be passed to the PDO Constructor, for example, changing the error mode. To facilitate this, a PDO specific settable array ADOConnection::pdoParameters
is provided:
$db = newAdoConnection('pdo\firebird'); $db->pdoParameters = [ \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION ]; $dsnString= 'host=localhost;dbname=employee.fdb'; $db->connect($dsnString,"SYSDBA", "password");
The PDO setAttribute function
For parameters that are set after the class is instantiated, The PDO::setAttribute() method can be populated using setConnectionParameter().
Individual Driver Status
Firebird
Sample Connection String
include 'adodb-dir/adodb.inc.php'; $db = ADOnewConnection('pdo\firebird'); $dsn = 'dbname=employee.fdb;hostname=localhost'; $user = 'SYSDBA'; $pass = 'master-key'; $db->connect($dsn,$user,$pass);
IBM DB2
- This driver requires the installation of the IBM DB2 client
- See the Preferred Driver page for more information about building DSNs for use with DB2 connections.
Sample Connection String
include 'adodb-dir/adodb.inc.php'; $db = ADOnewConnection('pdo\ibm'); $dsn = 'hostname=192.168.86.141;protocol=tcpip;port=25010;'; $dsn.= 'database=SAMPLE;uid=db2inst1;pwd=somepassword'; $user = ''; $password = '' $db->connect($dsn,$user,$password);
IBM Informix
PDO Name
pdo_informix
- There is no native mode driver for IBM Informix Connections
- This driver requires the installation of the IBM Informix Client
- Supports Informix Databases version 12+
Sample Connection String
include 'adodb-dir/adodb.inc.php'; $db = ADOnewConnection('pdo\informix'); $dsn = 'hostname=192.168.86.141;service=ol_informix1410;database=stores_demo;'; $dsn.= 'server=ol_informix1410;protocol=onsoctcp;EnableScrollableCursors=1;'; $user = 'ix-user'; $password = 'ix-password' $db->connect($dsn,$user,$password);
MySQL
Sample Connection String
include 'adodb-dir/adodb.inc.php'; $db = ADOnewConnection('pdo\mysql'); $dsn = 'hostname=127.0.0.1;database=employees;' $user = 'user'; $password = 'password' $db->connect($dsn,$user,$password);
ODBC
PDO Name
pdo_odbc
- This is a simple driver for connection to any ODBC compliant database.
- It is useful for reading and simple writes to data sources such as Microsoft Access, Excel and Google Sheets
- There is no support for Data Dictionary functions or database specific items such as sequences.
Sample Connection String
include 'adodb-dir/adodb.inc.php'; $db = ADOnewConnection('pdo\odbc'); /* * Points directly at the DSN configuration in Windows Control Panel */ $dsn = 'MYDSN' $db->connect($dsn);
Oracle
- There is no support for the complex binding features available in the Native Driver
- This driver requires installation of an Oracle client, such as InstantClient
Sample Connection String
If you are using the instantclient, and there is no tsnames.ora defined, you can define a connection like this
$db = newAdoConnection('pdo\oci'); //Connecting to Oracle Express on 192.168.86.86 $tns = " (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.86.86)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = XEPDB1) ) ) "; $dsnString="dbname=$tns"; $db->connect($dsnString,$userName,$password);
Postgres
Sample Connection String
$db = newAdoConnection('pdo\pgsql'); $dsn = 'pgsql:host=192.168.0.212;dbname=dvdrental'; $user = 'someuser'; $pass = 'somepass'; $db->connect($dsn,$user,$pass);
SQLite
Sample Connection String
include 'adodb-dir/adodb.inc.php'; $db = ADOnewConnection('pdo\sqlite'); $dsn = '/home/sqlite/adodb-sqlite.db'; $user = 'root'; $db->connect($dsn,$user);
SQL Server
- This driver requires the installation of the Microsoft native client library, as well as the Microsoft SQL Server PDO drivers for PHP
- Dates are always returned as strings
- This driver can also be used on Linux platforms, beginning with PHP Version 7. The program relies on the Microsoft drivers for Linux. For more information, see the mssqlnative driver
- You cannot change the character set in the driver. This is a limitation of the PDO driver, not ADOdb
Sample Connection String
include 'adodb-dir/adodb.inc.php'; $db = ADOnewConnection('pdo\sqlsrv'); $user = 'user'; $pass = 'password'; $dsn ='server=SERVER\SQLEXPRESS;database=NORTHWND;'; $db->connect($dsn,$user,$password);