PDO vs MySQL

pdo1

MySQL is most popular free open source database server which is developed by Oracle Corporation. This system is very reliable, easy and fast to use. It is commonly use with PHP to create dynamic server side scripting. MySQL is relational Database Management System that uses Structured Query Language. Main con of MySQL is that it supports only one driver whereas PDO support about 12 drivers to execute script of MySQL. So, if we want to switch our project to another database, PDO makes the process easy. We have to change only the connection string and a few queries but with MySQL, we need to rewrite the entire code. PDO stands for PHP Data Object.

PDO is PHP extension for creating connectivity with database or accessing database in PHP. It cannot perform database function using PDO extension, it require database specific PDO driver to access database server. It provides method for prepared statement and working with objects. PDO provides a data access abstraction layer. It provides Object Oriented API, which is easy to understand and learn. Main advantage of PDO is that it supports about 12 drivers.

Difference between MySQL and PDO:

Features PDO MySQL
Database Support 12 different Drivers MySQL only
API Only OOP OOP and Procedural
Named Parameter Yes No
Prepared Statement Yes No
Performance Slow Fast
     

MySQL

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

PDO

<?php
$servername = "localhost";
$username = "abcd";
$password = "passwd";

try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>

for more info : cpd-india

Batches: Regular & Weekends for Working Profession

For FREE DEMO CLASS CALL – 011-65164822 / 91- 8860352748

CPD Technologies
Block C 9/8, Sector -7, Rohini, Delhi-110085, India
Landmark: Near Rohini East Metro Station, Opposite Metro Pillar No-397

Website :- www.cpd-india.com

Email :- support@cpd-india.com

Your email address will not be published. Required fields are marked *

Contact CPD Technologies






    [recaptcha]