This is an old revision of the document!
PDO
See Also
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 drivers:
PHP Driver | Description | ADOdb Connector |
---|---|---|
pdo_firebird | Firebird | firebird |
pdo_mssql | SQL Server with FREETDS | mssql |
pdo_mysql | MySQL | mysql |
pdo_oci | Oracle | oci |
pdo_pgsql | Postgresql | pgsql |
pdo_sqlite | SQLite | sqlite |
pdo_sqlsrv | SQL Server using Windows Native Client | sqlsrv |
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
Microsoft native mode driver For Linux
FreeTDS Driver For Unix
Specification
Driver Name | pdo |
---|---|
Data Provider | pdo |
Status | Inactive1) |
Windows | No |
Unix | Yes |
ADOdb V5 | Yes |
ADOdb V6 | Yes |
The current status of this driver is unknown. Consider using the mssqlnative driver instead.
pdo_mysql
Preferred Driver
Specification
Driver Name | pdo |
---|---|
Data Provider | pdo |
Status | Active2) |
Windows | Yes |
Unix | No |
ADOdb V5 | Yes |
ADOdb V6 | Yes |
- Some Meta functions are unavailable
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
Specification
Driver Name | pdo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Data Provider | pdo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Status | Active3)WindowsYesUnixYesADOdb V5YesADOdb 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 DriverSpecification
=== 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 DriverSpecification
=== 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 ==== This driver is available from version 5.21 Native DriverSpecification
1)
This driver is not supported by ADOdb project members, but you can contribute to this driver if you have the expertise 3)
This driver is supported by ADOdb project members)|
=== 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 Driverpostgres9Specification
|