ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:database:pdo

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
v5:database:pdo [2019/01/03 03:25] – [pdo_pgsql] Added sample connection mnewnhamv5:database:pdo [2022/02/11 12:01] – [Description] move info about pdo driver usage to wrap dregad
Line 1: Line 1:
 ====== PDO ====== ====== PDO ======
 ~~NOTOC~~ ~~NOTOC~~
-<WRAP right box> +
-== See Also == +
-[[http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers|Tutorial On PDO Connections]] +
-</WRAP>+
 ===== Description ===== ===== Description =====
-This driver supports connections using the standardized [[http://php.net/manual/en/book.pdo.php|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) +This driver supports connections using the standardized [[http://php.net/manual/en/book.pdo.php|PHP Data Objects]].  
-  pdo_mysql (MySQL) + 
-  pdo_oci (Oracle) +Supported drivers: 
-  pdo_pgsql (Postgresql) + 
-  pdo_sqlite (SQLite) +^PHP Driver^Description^ADOdb Connector^ 
-  pdo_sqlsrv (SQL Server with Windows)+|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| 
 +  
 +<WRAP important> 
 +Note that the //pdo// driver cannot be used on its own. It is a technical component that is used internally by the above drivers.  
 +</WRAP> 
  
 ===== Establishing A Connection ===== ===== Establishing A Connection =====
Line 23: Line 30:
 $user     = 'pdo-user'; $user     = 'pdo-user';
 $password = 'pdo-pass'; $password = 'pdo-pass';
-$dsnString= 'host=localhost;dbname=employees;charset=utf8mb4'+$dsnString= 'host=localhost;dbname=employees;charset=utf8mb4';
 $db->connect('mysql:' . $dsnString,$user,$password); $db->connect('mysql:' . $dsnString,$user,$password);
  
Line 32: Line 39:
  
 ===== Preferred Drivers ===== ===== Preferred Drivers =====
-In all cases, using native drivers (listed below) provide better functionality, as well as performance, than the equivalent PDO driver.+ 
 +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. 
 +  * In all cases, 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 [[https://www.php.net/manual/en/pdo.construct.php|PDO Constructor]], for example, changing the error mode. To facilitate this, a PDO specific settable array **'' ADOConnection::pdoOptions ''** is provided: 
 + 
 +<code php> 
 +$db = newAdoConnection('pdo'); 
 + 
 +$db->pdoOptions = [ 
 +\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION 
 +]; 
 + 
 +$dsnString= 'host=localhost;dbname=employee.fdb'; 
 +$db->connect('firebird:' . $dsnString,"SYSDBA", "password"); 
 + 
 +</code> 
 ===== The PDO setAttribute function ===== ===== The PDO setAttribute function =====
-As of ADOdb 5.21the PDO::setAttribute() method can be emulated using [[v5:reference:connection:setconnectionparameter|setConnectionParameter()]].+For parameters that are set after the class is instantiatedThe PDO::setAttribute() method can be populated using [[v5:reference:connection:setconnectionparameter|setConnectionParameter()]]. 
 ===== Individual Driver Status ==== ===== Individual Driver Status ====
 ----------------------- -----------------------
Line 66: Line 95:
 ^ADOdb V6|Yes| ^ADOdb V6|Yes|
 </WRAP> </WRAP>
 +
   * Some **//Meta//** functions are unavailable   * Some **//Meta//** functions are unavailable
  
-==== Sample Connection String ====+ 
 +------------------------------------------------------- 
 +=== Sample Connection String ===
 <code php> <code php>
 include 'adodb-dir/adodb.inc.php'; include 'adodb-dir/adodb.inc.php';
-$db = ADOnewConnection('pdo');+$db   = ADOnewConnection('pdo'); 
 + 
 +$dsn  = 'mysql:hostname=127.0.0.1;database=employees;'
 $user = 'user'; $user = 'user';
 $password = 'password' $password = 'password'
-$db->connect('mysql:hostname=127.0.0.1;database=employees;',$user,$password);+ 
 +$db->connect($dsn,$user,$password);
 </code> </code>
 ---------------------------------------------- ----------------------------------------------
Line 84: Line 119:
 ^Driver Name|pdo| ^Driver Name|pdo|
 ^Data Provider|pdo| ^Data Provider|pdo|
-^Status|Inactive((This driver is not supported by ADOdb project members, but you can contribute to this driver if you have the expertise))|+^Status|Active((This driver is supported by ADOdb project members))|
 ^Windows|Yes| ^Windows|Yes|
-^Unix|No|+^Unix|Yes|
 ^ADOdb V5|Yes| ^ADOdb V5|Yes|
 ^ADOdb V6|Yes| ^ADOdb V6|Yes|
 </WRAP> </WRAP>
-The current status of this driver is unknown+== Limitations == 
 + 
 + 
 +  * There is no support for the complex binding features available in the Native Driver 
 +  * Some MetaFunctions are unavailable 
 + 
 +---------------------------------------- 
 +=== Sample Connection String === 
 +If you are using the instantclient, and there is no tsnames.ora defined, you can define a connection like this 
 +<code php> 
 + 
 +//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); 
 + 
 +</code>
 ------------------------------------------ ------------------------------------------
 ==== pdo_pgsql ==== ==== pdo_pgsql ====
Line 101: Line 161:
 ^Status|Active((This driver is supported by ADOdb project members))| ^Status|Active((This driver is supported by ADOdb project members))|
 ^Windows|Yes| ^Windows|Yes|
-^Unix|No|+^Unix|Yes|
 ^ADOdb V5|Yes| ^ADOdb V5|Yes|
 ^ADOdb V6|Yes| ^ADOdb V6|Yes|
 </WRAP> </WRAP>
-===== Status =====+=== Status ===
 Some features are not supported Some features are not supported
-===== Sample Connection String =====+--------------------------------------------------------------- 
 +=== Sample Connection String ===
 <code php> <code php>
 $db = newAdoConnection('pdo'); $db = newAdoConnection('pdo');
-$dsnString= 'host=192.168.0.212;dbname=dvdrental';+ 
 +$dsn  = 'pgsql:host=192.168.0.212;dbname=dvdrental';
 $user = 'someuser'; $user = 'someuser';
-$password = 'somepass'; +$pass = 'somepass'; 
-$db->connect('pgsql:'$dsnString,$someuser,$somepass);+ 
 +$db->connect($dsn,$user,$pass);
 </code> </code>
  
Line 130: Line 193:
 ^ADOdb V6|Yes| ^ADOdb V6|Yes|
 </WRAP> </WRAP>
- +---------------------------------------------------------------- 
-==== Sample Connection String ====+=== Sample Connection String ===
 <code php> <code php>
 include 'adodb-dir/adodb.inc.php'; include 'adodb-dir/adodb.inc.php';
 $db = ADOnewConnection('pdo'); $db = ADOnewConnection('pdo');
-$db->connect('sqlite:/home/sqlite/adodb-sqlite.db','root');+ 
 +$dsn  = 'sqlite:/home/sqlite/adodb-sqlite.db'
 +$user = 'root'
 + 
 +$db->connect($dsn,$user);
 </code> </code>
----------------------------------------+ 
 +------------------------------------------------- 
 ==== pdo_sqlsrv ==== ==== pdo_sqlsrv ====
 <WRAP right box round 300px> <WRAP right box round 300px>
Line 156: Line 225:
   * Dates are always returned as strings   * Dates are always returned as strings
   * Most //**Meta**// functions are unsupported   * Most //**Meta**// functions are unsupported
-  * [[v5:reference:connection:setconnectionparameter|setConnectionParameter()]] is not supported, so changing the character set at run-time is not available.+  * [[v5:reference:connection:setconnectionparameter|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 [[v5:database:microsoft_sql_server|mssqlnative driver]]   * 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 [[v5:database:microsoft_sql_server|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 ====+=== Sample Connection String ===
 <code php> <code php>
 include 'adodb-dir/adodb.inc.php'; include 'adodb-dir/adodb.inc.php';
 $db = ADOnewConnection('pdo'); $db = ADOnewConnection('pdo');
 +
 $user = 'user'; $user = 'user';
-$password = 'password' +$pass = 'password'; 
-$db->connect('sqlsrv:server=SERVER\SQLEXPRESS;database=NORTHWND;',$user,$password);+$dsn  ='sqlsrv:server=SERVER\SQLEXPRESS;database=NORTHWND;'
 + 
 +$db->connect($dsn,$user,$password);
 </code> </code>
  
 +-----------------------------------------------------------------------------
 +
 +==== pdo_firebird ====
 +<WRAP right box round 300px>
 +== Native Driver ==
 +[[v5:database:firebird|Firebird/Interbase Driver]]\\
 +== Specification ==
 +^Driver Name|pdo|
 +^Data Provider|pdo|
 +^Status|Active((This driver is supported by ADOdb project members))|
 +^Windows|Yes|
 +^Unix|Yes|
 +^ADOdb V5|Yes|
 +^ADOdb V6|Yes|
 +</WRAP>
 +Unlike other pdo drivers, pdo_firebird is the preferred driver for this database. This is due to specific issues with this driver reported [[https://bugs.php.net/bug.php?id=72175|here]]. 
 +
 +------------------------------------------------------------
 +=== Sample Connection String ===
 +
 +<code php>
 +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);
 +
 +</code>
  
 +{{tag>tier2}}
  
v5/database/pdo.txt · Last modified: 2022/02/20 23:47 by mnewnham