How to use PDO database connection in PHP
Mysql 10-Nov-2016

How to use PDO database connection in PHP

As we all know that in PHP 5.5 MySQL is deprecated and we have to move new extensions like MyQLi or PDO (PHP Data Objects) for database integration, we have already publish an article on How to use MySQLi_connect PHP and this article will explain you how to connect with MySQL database using PDO connection and we explain very few things in this tutorial like database connection, insert, delete, update and select queries with prepare statement, multiple insert and error handling.

Connection

You all knows the old style of connecting to MySQL database:

<?php
# Connect
mysql_connect('localhost', 'database_user', 'database_password') or die('Could not connect: ' . mysql_error());
?>

Using PDO we create a new instance of the class, and describe the name of driver, database name, database user and database password: