In short , PDO extensions defines a set of php extensions which provides the interface for accessing the database in php.
It is the light weight process .
It provides the core PDO class and databases for specific drives.
Each drivers that implements the PDO interface act as the database-specific fearures as regular extension functions.
PDO provides us the vendor-neutral, lightweight, data-access abstraction layer , so for this reasons , it doesn’t matter which database we are using , you can use the same functions and to issue the queries and fetch the data .
PDO does not focus on database abstraction rather on data access abstraction.
The basic requirement for PDO is the core of php 5+, i.e the new object oriented features , So for this reasons it will not execute with earlier versions of PHP .
The PDO consists of components
The core for interface and Drivers to access the certain driver.
Let Set the connection using PDO :
$hostname = “localhost”;
$username = “username”;
$password = “password”;
$conn = new PDO(“mysql:host=$hostname;dbname=myDB”, $username, $password);
// seting the PDO error to exception
echo “Connection established successfully”;
echo “Failed to Connect: ” . $e->getMessage();