Adodb Pdo Presentation

4,684 views
4,356 views

Published on

Comparison and examples of database abstraction with ADOdb and PDO

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,684
On SlideShare
0
From Embeds
0
Number of Embeds
228
Actions
Shares
0
Downloads
68
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Adodb Pdo Presentation

  1. 1. PHP: ADOdb or PDO for DB Access Tom Rogers Northwestern University Department of Anesthesiology
  2. 2. Definition of Database Access <ul><li>A database abstraction layer is an application programming interface which unifies the communication between a computer application and databases such as PostgreSQL , Oracle or SQLite . (Wikipedia) </li></ul><ul><li>Database abstraction layers reduce the amount of work by providing a consistent API to the developer and hide the database specifics behind this interface as much as possible. (Wikipedia) </li></ul>
  3. 3. DB Access/Abstraction Libraries/Classes Available <ul><li>PHP Native Libraries </li></ul><ul><ul><li>Mysql, Msqli </li></ul></ul><ul><ul><li>Pgsql </li></ul></ul><ul><li>Pear:DB </li></ul><ul><li>Pear:MDB2 </li></ul><ul><li>ADOdb </li></ul><ul><li>PDO </li></ul>
  4. 4. ADOdb <ul><li>ADOdb is a database abstraction library for PHP and Python based on the same concept as Microsoft's ActiveX Data Objects . </li></ul><ul><li>It allows developers to write applications in a fairly consistent way regardless of the underlying database storing the information. </li></ul><ul><li>The advantage is that the database can be changed without re-writing every call to it in the application. </li></ul><ul><li>(Wikipedia) </li></ul>
  5. 5. PDO PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. (PHP Documentation)
  6. 6. DB Connections <ul><li>ADOdb: </li></ul><ul><ul><li>include('/path/to/adodb.inc.php'); </li></ul></ul><ul><ul><li>$ado = NewADOConnection('mysql'); </li></ul></ul><ul><ul><li>$ado->Connect($server, $user, $pwd, $database); </li></ul></ul><ul><li>ADOdb(dsn): </li></ul><ul><ul><li>Include('/path/to/adodb.inc.php'); </li></ul></ul><ul><ul><li>$ado = NewADOConnection(“mysql://$user:$pwd@$server/$database”); </li></ul></ul><ul><li>PDO: </li></ul><ul><ul><li>As of PHP 5.1 no extensions needed, although db driver has to be enabled </li></ul></ul><ul><ul><li>$pdo = new PDO('mysql:host=localhost;dbname=database',”$user”,”$pwd”); </li></ul></ul>
  7. 7. ADOdb: SQL Query and Iteration <ul><li>$sql = “select pk, description from tbl_demo”; </li></ul><ul><li>ADOdb: (multi-record dataset) </li></ul><ul><ul><li>foreach($ado->Execute($sql) as $row){ </li></ul></ul><ul><ul><li>$pk = $row['pk']; </li></ul></ul><ul><ul><li>$description = $row['description']; </li></ul></ul><ul><ul><li>... process code ... </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>ADOdb: (single record) </li></ul><ul><ul><li>$row = $ado->GetRow($sql); </li></ul></ul><ul><ul><li>$pk = $row['pk']; </li></ul></ul><ul><ul><li>$description = $row['description']; </li></ul></ul>
  8. 8. PDO: SQL Query and Iteration <ul><li>$sql = “select pk, description from tbl_demo”; </li></ul><ul><li>PDO: </li></ul><ul><ul><li>foreach($pdo->query($sql) as $row){ </li></ul></ul><ul><ul><li>$pk = $row['pk']; </li></ul></ul><ul><ul><li>$description = $row['description']; </li></ul></ul><ul><ul><li>... process code ... </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>As far as I can tell, there is no PDO equivalent to ADOdb's “GetRow” method. </li></ul>
  9. 9. Functions Available <ul><li>ADOdb (http://phplens.com/adodb/) </li></ul><ul><ul><li>Connection Management </li></ul></ul><ul><ul><li>DB Dictionary Library </li></ul></ul><ul><ul><li>DB-backed Sessions </li></ul></ul><ul><ul><li>DB Perform. Monitoring </li></ul></ul><ul><ul><li>Pagination of Record Sets </li></ul></ul><ul><ul><li>Blob Handling </li></ul></ul><ul><ul><li>Transactions </li></ul></ul><ul><ul><li>String, Date Manipulation </li></ul></ul><ul><ul><li>Error Handling </li></ul></ul><ul><ul><li>CSV Export </li></ul></ul><ul><li>PDO ( http://us2.php.net/pdo ) </li></ul><ul><ul><li>Connection Management </li></ul></ul><ul><ul><li>Prepared Statements/Stored Procedures </li></ul></ul><ul><ul><li>Large Objects (LOB) </li></ul></ul><ul><ul><li>Transactions </li></ul></ul><ul><ul><li>Error Handling </li></ul></ul>
  10. 10. Benchmarks http://joseph.randomnetworks.com/archives/2006/04/04/php-database-functions-vs-peardb-vs-adodb/

×