ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:database:pdo_new

This is an old revision of the document!


PDO

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


Supported drivers

PHP DriverDescriptionADOdb Connector
pdo_firebirdFirebirdfirebird
pdo_ibmIBM DB2db2
pdo_informixIBM Informixinformix
pdo_mysqlMySQLmysql
pdo_ociOracleoci
pdo_odbcGeneric ODBC
pdo_pgsqlPostgresqlpgsql
pdo_sqliteSQLitesqlite
pdo_sqlsrvSQL Server using Windows Native Clientsqlsrv

Unsupported Drivers

  • pdo_mssql
  • pdo_dblib
  • pdo_cubrid

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:

  • It provides true database abstraction, for example, the ADOdb method 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.
  • Unless otherwise described below, using native drivers (listed below) provide better functionality, as well as performance, than the equivalent PDO driver. This is true at both the ADOdb and PHP level

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

  • This driver requires the installation of the IBM DB2 client

Sample Connection String

include 'adodb-dir/adodb.inc.php';
$db   = ADOnewConnection('pdo\ibm');
 
$dsn = 'hostname=192.168.86.141;protocol=tcpip;port=50000;';
$dsn.= 'database=SAMPLE;uid=db2inst1;pwd=somepassword';
$user = '';
$password = ''
 
$db->connect($dsn,$user,$password);

IBM Informix

PDO Name

pdo_informix

  • There is no native mode driver for IBM Informix Connections
  • This driver requires the installation of the IBM Informix Client

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

Oracle

PDO Name

pdo_oci

Preferred Driver

oci8

  • There is no support for the complex binding features available in the Native Driver
  • This driver requires installation of an Oracle client, such as InstantClient

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

pdo_sqlite

Preferred Driver

SQLite Database

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

pdo_sqlsrv

Preferred Driver

Native Mode Driver

Specification
Driver Namepdo
Data Providerpdo
StatusActive3)
WindowsYes
UnixYes
ADOdb V5Yes
ADOdb V6Yes
  • This driver requires the installation of the Microsoft native client library, as well as the Microsoft SQL Server PDO drivers for PHP
  • Dates are always returned as strings
  • Most Meta functions are unsupported
  • setConnectionParameter() is not supported
  • This driver can also be used on Linux platforms, beginning with PHP Version 7. The program relies on the Microsoft drivers for Linux. For more information, see the mssqlnative driver
  • You cannot change the character set in the driver. This is a limitation of the PDO driver, not ADOdb
  • No support for parameter binding

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

1) , 2) , 3)
This driver is supported by ADOdb project members
v5/database/pdo_new.1647798171.txt.gz · Last modified: 2022/03/20 18:42 by mnewnham