PDO MySQL


 

PDO MySQL

In this tutorial we will study about PDO MySQL in PHP, how to access MySQL using PDO, etc. Examples will make this clearer.

In this tutorial we will study about PDO MySQL in PHP, how to access MySQL using PDO, etc. Examples will make this clearer.

PDO MySQL:

MySQL is one of the most popular open source database, in this current tutorial we will come to know how to connect MySQL with PHP using PDO.

Most of the web developers use MySQL with PHP, and most of the examples in our tutorial you will see that we have used this database. Following and further examples will be based on MySQL.

Example:

<?php

$hostname = 'localhost';// mysql hostname

$username = 'root';// mysql username

$password = '';// mysql password

try {

$dbh = new PDO("mysql:host=$hostname;dbname=roseindia", $username, $password);

echo 'Connected to database';//display a message saying we have connected

echo "Select * from student";

}

catch(PDOException $e)

{

echo $e->getMessage();

}

?>

 

Output:

Connected to database

Ads