PDO : PHP Data Object
PDO is an acronym for PHP Data Objects.
It is a database access layer providing a uniform method of access to multiple databases.
Use of PDO :
Let a suppose you need to connect your database to Oracle or IBM DB2 in your existing code(written in MySQL/PHP) or if you want to use/connect 2 types of database on different platforms in your project,then in that case you have to use so many APIs and it will very annoying, second option is simply use PDO extension/library for all the database related stuff.It will very easy to use and work fast rather then the traditional code.
PDO is available in PHP5.1 or more,It’s written in C,so you know it’s fast.
PDO is simply PHP extension to formalize PHP’s database connections by creating a uniform interface.This allows developers to create code which is portable across many databases and platforms.
The extension can support any database that a PDO driver has been written for.You can get available drivers by the code.
foreach(PDO::getAvailableDrivers() as $driver)
There are so many Predefined Constants available in PDO.Below is the list of some(MYSQL) of those.These are very useful during the coding and database program.
We can connect any of the database using PDO, here is the example of MySQL and Oracle.
Connect to MySQL
$hostname = ‘localhost’;
$username = ‘username’;
$password = ‘password’;
$dbh = new PDO(“mysql:host=$hostname;dbname=mysql”, $username, $password);
echo ‘Connected to database’;
Connect to Oracle
$dbh = new PDO(“OCI:”, “username”, “password”)
catch (PDOException $e)
All the database related commands create/update/insert/delete/alter/rename/drop are available in PDO.
The new PHP Frameworks and the PHP Open-source new versions uses PDO.
For more information and complete guide of PDO, you can go to the below links.