ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:database:pdo

PDO

Description

This driver supports connections using the standardized PHP Data Objects connection. The pdo driver itself cannot be used, it must be used with one of the supported databases:

  • pdo_mssql (SQL Server with FREETDS)
  • pdo_mysql (MySQL)
  • pdo_oci (Oracle)
  • pdo_pgsql (Postgresql)
  • pdo_sqlite (SQLite)
  • pdo_sqlsrv (SQL Server with Windows)

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

In all cases, using native drivers (listed below) provide better functionality, as well as performance, than the equivalent PDO driver.

The PDO setAttribute function

As of ADOdb 5.21, the PDO::setAttribute() method can be emulated using setConnectionParameter().

Individual Driver Status


pdo_mssql

Preferred Driver

FreeTDS Driver For Unix

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

The current status of this driver is unknown


pdo_mysql

Preferred Driver

mysqli

Specification
Driver Namepdo
Data Providerpdo
StatusActive2)
WindowsYes
UnixNo
ADOdb V5Yes
ADOdb V6Yes
  • Some Meta functions are unavailable

Sample Connection String

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

pdo_oci

Preferred Driver

oci8

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

The current status of this driver is unknown


pdo_pgsql

Preferred Driver

postgres9

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

The current status of this driver is unknown


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');
$db->connect('sqlite:/home/sqlite/adodb-sqlite.db','root');

pdo_sqlsrv

Preferred Driver

Native Mode Driver
ODBC Driver for SQL Server

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

Sample Connection String

include 'adodb-dir/adodb.inc.php';
$db = ADOnewConnection('pdo');
$user = 'user';
$password = 'password'
$db->connect('sqlsrv:server=SERVER\SQLEXPRESS;database=NORTHWND;',$user,$password);
1) , 3) , 4) This driver is not supported by ADOdb project members, but you can contribute to this driver if you have the expertise
2) , 5) , 6) This driver is supported by ADOdb project members
v5/database/pdo.txt · Last modified: 2016/05/20 15:45 by mnewnham