Why should we use PDO(PHP Data Object)?

PDO, The PHP Data Object extension is a data-access abstraction layer supports multiple databases(Mysql, SqlLite, PostGreSql). PDO is shipped with PHP 5.1

If you uses framework, you don’t have to do that, you use the database class,methods to handle this. If you are building application from scratch, you may build database class to interact with database with a list of methods. Thus PDO is perfact for you because

This extension has all the methods to get/set value with databases.
Excellent error trapping methods (following code is to connect with mysql database). See below –

$dsn = 'mysql:host=localhost;dbname=world;';
$user = 'user';
$password = 'secret';
$dbh = new PDO($dsn, $user, $password);
catch (PDOException $e)
echo 'Connection failed: ' . $e->getMessage();

Mysql errors trapping methods.
Method to protect SQL injection attack.
Today’s popular E-Commerce tool Magento uses PDO. It’s excellent php extension so far.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.