This is still under development. Feedback is welcome, just add your comments in the pull request.
Driver Name | pdo |
---|---|
Data Provider | pdo |
Status | Active1) |
Windows | Yes |
Unix | Yes |
ADOdb V5 | Yes |
ADOdb V6 | Yes |
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.)
newAdoConnection('pdo')
, use newAdoConnection('pdo\driver')
newAdoConnection()
is no longer supportedPHP 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 |
Note that the pdo driver cannot be used on its own. It is a technical component that is used internally by the above drivers.
To establish a connection:
ADONewConnection()
function call 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);
Using ADOdb effectively eliminates the need to use the PHP PDO driver as it hides the PHP level command:
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.
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");
For parameters that are set after the class is instantiated, The PDO::setAttribute() method can be populated using setConnectionParameter().
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);
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);
pdo_informix
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);
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);
pdo_odbc
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);
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);
$db = newAdoConnection('pdo\pgsql'); $dsn = 'pgsql:host=192.168.0.212;dbname=dvdrental'; $user = 'someuser'; $pass = 'somepass'; $db->connect($dsn,$user,$pass);
include 'adodb-dir/adodb.inc.php'; $db = ADOnewConnection('pdo\sqlite'); $dsn = '/home/sqlite/adodb-sqlite.db'; $user = 'root'; $db->connect($dsn,$user);
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);