Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PHP Data Objects (PDO)

PHP Data Objects, aka PDO, is an interface that abstract access to databases. The same interface may be used to access different databases.

PDO provides access 10 different databases:

  • CUBRID
  • MS SQL Server
  • Firebird
  • IBM
  • Informix
  • MySQL
  • MS SQL Server
  • Oracle
  • ODBC and DB2
  • PostgreSQL
  • SQLite 2 and 3

The different access relies on drivers and DSN to connect to a database. The DSN describes the server to reach, and the driver handles the communication protocol.

<?php
  $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
?>

Documentation