PDO

Description

This driver supports connections using the standardized PHP Data Objects.

Supported drivers:

PHP DriverDescriptionADOdb Connector
pdo_firebirdFirebirdfirebird
pdo_mssqlSQL Server with FREETDSmssql
pdo_mysqlMySQLmysql
pdo_ociOracleoci
pdo_pgsqlPostgresqlpgsql
pdo_sqliteSQLitesqlite
pdo_sqlsrvSQL Server using Windows Native Clientsqlsrv

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 DSN style of connection must be used, the first argument of the DSN string being the database type, e.g. to connect to a MySQL database:

include_once 'adodb/adodb.inc.php';
$db = ADOnewConnection('pdo');
 
$user     = 'pdo-user';
$password = 'pdo-pass';
$dsnString= 'host=localhost;dbname=employees;charset=utf8mb4';
$db->connect('mysql:' . $dsnString,$user,$password);

Note that in the above example, the database type is separated from the rest of the DSN string by a : (colon). The rest of the DSN arguments are separated by a ; (semi-colon).

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');
 
$db->pdoParameters = [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION
];
 
$dsnString= 'host=localhost;dbname=employee.fdb';
$db->connect('firebird:' . $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


pdo_mssql

Preferred Driver

Microsoft native mode driver For Linux
FreeTDS Driver For Unix

Specification
Driver Namepdo
Data Providerpdo
StatusInactive1)
WindowsNo
UnixYes
ADOdb V5Yes
ADOdb V6Yes

The current status of this driver is unknown. Consider using the mssqlnative driver instead.


pdo_mysql

Preferred Driver

mysqli

Specification
Driver Namepdo
Data Providerpdo
StatusActive2)
WindowsYes
UnixNo
ADOdb V5Yes
ADOdb V6Yes

Sample Connection String

include 'adodb-dir/adodb.inc.php';
$db   = ADOnewConnection('pdo');
 
$dsn  = 'mysql:hostname=127.0.0.1;database=employees;'
$user = 'user';
$password = 'password'
 
$db->connect($dsn,$user,$password);

pdo_oci

Preferred Driver

oci8

Specification
Driver Namepdo
Data Providerpdo
StatusActive3)
WindowsYes
UnixYes
ADOdb V5Yes
ADOdb V6Yes
Limitations

Sample Connection String

If you are using the instantclient, and there is no tsnames.ora defined, you can define a connection like this

//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="oci:dbname=$tns";
$db->connect($dsnString,$userName,$password);

pdo_pgsql

Preferred Driver

postgres9

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

Status

Some features are not supported


Sample Connection String

$db = newAdoConnection('pdo');
 
$dsn  = 'pgsql:host=192.168.0.212;dbname=dvdrental';
$user = 'someuser';
$pass = 'somepass';
 
$db->connect($dsn,$user,$pass);

pdo_sqlite

Preferred Driver

SQLite Database

Specification
Driver Namepdo
Data Providerpdo
StatusActive5)
WindowsYes
UnixNo
ADOdb V5Yes
ADOdb V6Yes

Sample Connection String

include 'adodb-dir/adodb.inc.php';
$db = ADOnewConnection('pdo');
 
$dsn  = 'sqlite:/home/sqlite/adodb-sqlite.db';
$user = 'root';
 
$db->connect($dsn,$user);

pdo_sqlsrv

Preferred Driver

Native Mode Driver

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

Sample Connection String

include 'adodb-dir/adodb.inc.php';
$db = ADOnewConnection('pdo');
 
$user = 'user';
$pass = 'password';
$dsn  ='sqlsrv:server=SERVER\SQLEXPRESS;database=NORTHWND;';
 
$db->connect($dsn,$user,$password);

pdo_firebird

Native Driver

Firebird/Interbase Driver

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

Unlike other pdo drivers, pdo_firebird is the preferred driver for this database. This is due to specific issues with this driver reported here.


Sample Connection String

include 'adodb-dir/adodb.inc.php';
$db = ADOnewConnection('pdo');
 
$dsn  = 'firebird:dbname=employee.fdb;hostname=localhost';
$user = 'SYSDBA';
$pass = 'master-key';
 
$db->connect($dsn,$user,$pass);
1)
This driver is not supported by ADOdb project members, but you can contribute to this driver if you have the expertise
2) , 3) , 4) , 5) , 6) , 7)
This driver is supported by ADOdb project members