Code has been added to clipboard!

MySQL Connecting With PHP Data Objects

Example
<?php
  $servername = "localhost";
  $username = "name_of_the_user";  
  $password = "users_password";

  try 
  { 
     $conn = new PDO("mysql:host=$servername; dbname=myDatabase", $username, $password);
     $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);    
     echo "Connected successfully";
  }
  catch(PDOException $e)    
  {      	
     echo "Failed to connect:  " . $e->getMessage();    
  }  
?>