1 / 24

PHP Data Object (PDO)

PHP Data Object (PDO). What is PDO?. PDO is a PHP extension to formalise PHP's database connections by creating a uniform interface. This allows developers to create code which is portable across many databases and platforms.

Download Presentation

PHP Data Object (PDO)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PHP Data Object (PDO)

  2. What is PDO? • PDO is a PHP extension to formalise PHP's database connections by creating a uniform interface. This allows developers to create code which is portable across many databases and platforms. • PDO is not just another abstraction layer like PEAR DB or ADOdb.

  3. Why use PDO? • Portability • Performance • Power • Easy • Runtime Extensible

  4. What databases does it support? • Microsoft SQL Server / Sybase • Firebird / Interbase • DB2 / INFORMIX (IBM) • MySQL • OCI (Oracle Call Interface) • ODBC • PostgreSQL • SQLite

  5. DSNs • In general drivername:<driver-specific-stuff> • mysql:host=name;dbname=dbname • odbc:odbc_dsn • oci:dbname=dbname;charset=charset • sqlite:/path/to/db/file • sqlite::memory:

  6. Connect to MySQL

  7. Connect to SQLite (file)

  8. Connect to SQLite (memory)

  9. Connect to Oracle

  10. Connect to ODBC

  11. Close a Database Connection

  12. Persistent PDO Connection • Connection stays alive between requests $dbh = new PDO($dsn, $user, $pass, array( PDO_ATTR_PERSISTENT => true ) );

  13. PDO Query (INSERT)

  14. PDO Query (UPDATE)

  15. PDO Query (SELECT)

  16. Error Handling (1)

  17. Error Handling (2)

  18. Error Handling (3)

  19. Error Handling (4)

  20. Prepared statements

  21. Transactions

  22. Get Last Insert Id

  23. Benchmark

  24. Questions

More Related