how to connect database with pdo

today i will show , how to connect database with pdo.
step 1
go to your phpmyadmin and create a new db.
step 2
create a php file in your htdocs folder,like filename.php
step 3
then type the Following code blew.
  1. <?php
  2. $host = "localhost";
  3. $user = "root";
  4. $pass = "";
  5. $conn = new pdo ("mysql:host=$host;dbname=mydb,$user, $pass ");
  6. if($conn==true){
  7. echo"database connected";
  8. }

  9. ?>
 explanation of the variable that we have used in our filename.php file:
  1. $host will be the host where your server is running it is localhost.
  2. $user will be the username i.e. root and $pass will be the password which is  same that you  access your phpmyadmin.