Code has been added to clipboard!

MySQL Insert Into for PDO Users

Example
<?php
  $servername = 'localhost';
  $username = 'name_of_the_user';  
  $password = 'users_password';
  $dbname =   'myDatabase';

  try {    
    $conn = new PDO("mysql:host=$servername; dbname=$dbname", $username, $password); 
    // set the PDO error mode to exception    
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO MovieList (title, rating, price) VALUES ('random_movie', 'good', '5')"; 
 	  // use exec() because no results are returned
    $conn->exec($sql); 
    echo "Inserted successfully";
  } catch(PDOException $e) {
    echo $sql . "<br>" . $e->getMessage();  
  }  	
  $conn = null;  
?>