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 passwordtry
{ $dbh = new PDO("mysql:host=$hostname;dbname=roseindia", $username, $password); echo 'Connected to database';//display a message saying we have connectedecho "Select * from student";
}
catch
(PDOException $e){
echo $e->getMessage();}
?>
Output:
Connected to database
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.