Code has been added to clipboard!

MySQL Database Statement for PDO Users

Example
<?php
  $host = 'host';
  $user = 'user';  	
  $pass = 'pass';
  try {
    $conn = new PDO("mysql:host=$host;dbname=my_data", $user, $pass);      	
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    
    $sql = "CREATE DATABASE my_data";    
    // use exec() because no results are returned    
    $conn->exec($sql);      	
    echo "Database creation successful.<br>";
  } catch(PDOException $e)
  { 
    echo $sql . "<br>" . $e->getMessage();
  }
  $conn = null;  
?>