DatabaseServer;
$database = (string) $applicationSettings->DatabaseName;
$user = (string) $applicationSettings->DatabaseUser;
$password = (string) $applicationSettings->DatabasePassword;
try {
$connection = new PDO("mysql:host={$host};dbname={$database}", $user, $password);
$connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException | Exception $e) {
echo "Unable to connect to the database.
";
echo "Error is: {$e->getMessage()}";
exit();
}
// Create the table.
$connection->exec("set foreign_key_checks = 0");
$connection->exec("drop table if exists {$table}");
try {
$connection->exec($SQL);
} catch (PDOException | Exception $e) {
echo "Error creating table.
";
echo "Error is: {$e->getMessage()}";
exit();
}
if ($connection->errorCode() != 0) {
echo "Error creating table.
";
echo "
";
print_r($connection->errorInfo());
} else {
echo "Table {$table} was created.";
}
?>