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;
?>