PDO (new)

This is still under development. Feedback is welcome, just add your comments in the pull request.

Specification
Driver Namepdo
Data Providerpdo
StatusActive1)
WindowsYes
UnixYes
ADOdb V5Yes
ADOdb V6Yes

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'), use newAdoConnection('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 DriverDescriptionADOdb Connector
pdo_firebirdFirebirdfirebird
pdo_ibmIBM DB2ibm
pdo_informixIBM Informixinformix
pdo_mysqlMySQLmysql
pdo_ociOracleoci
pdo_odbcGeneric ODBCodbc
pdo_pgsqlPostgresqlpgsql
pdo_sqliteSQLitesqlite
pdo_sqlsrvMicrosoft SQL Serversqlsrv

Unsupported Drivers

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:

  1. The PDO database type must be specified in the ADONewConnection() function call
  2. 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:

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

PDO Name

pdo_firebird

Preferred Driver

Firebird/Interbase Driver


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

PDO Name

pdo_ibm

Preferred Driver

DB2


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


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

PDO Name

pdo_mysql

Preferred Driver

mysqli


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


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

PDO Name

pdo_oci

Preferred Driver

oci8


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

PDO Name

pdo_pgsql

Preferred Driver

postgres9


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

PDO Name

pdo_sqlite

Preferred Driver

SQLite Database


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

PDO Name

pdo_sqlsrv

Preferred Driver

Native Mode Driver


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);

1)
This driver is supported by ADOdb project members