Connect to MySQL database using PDO

Below is how to set up a PDO connection to a MySQL database.

<?php
 
define('DATABASE','db_name');
define('DATABASE_USER','db_user');
define('DATABASE_PASSWORD','db_password');
 
try {
  $db = new PDO('mysql:host=localhost;dbname='.DATABASE,
DATABASE_USER, DATABASE_PASSWORD,array(
    PDO::ATTR_PERSISTENT => true
  ));
} catch (PDOException $e) {
  print "Error!: " . $e->getMessage() . "<br/>";
  die();
}
 
?>