Share on Google+Share on Google+

PDO MySQL

Advertisement
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

Advertisements

Posted on: April 2, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.