PDO MySQL
Posted on: April 2, 2010 at 12:00 AM
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

Related Tags for PDO MySQL:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.