- ini_set: documentation ( source)
- error_reporting: documentation ( source)
- ini_get: documentation ( source)
<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(-1);
/**
* Created in PhpStorm.
* User: 750430
* Date: 04/03/2016
* Time: 20:52
*/
include __DIR__.'/db_settings.php';
// try/catch to connect to the db and create the database using a prepared statement if it doesn't exist.
try{
$pdo = new PDO("mysql:host' . HOST.'; charset='.CHARSET.';port='.POST.'", $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare("CREATE DATABASE IF NOT EXISTS $db");
$stmt->execute();
$results["meta"]["feedback"] = "Database created.";
return $results;
} catch (PDOException $e) {
echo 'Create DB failed: ' . $e->getMessage();
}
try{
$stmt = $pdo->prepare("USE $db");
$stmt->execute();
$error = 'use db';
throw new Exception($error);
} catch (PDOException $e) {
echo 'DB use failed: ' . $e->getMessage();
}
try{
$stmt = $pdo->query(DATABASE_INIT);
$stmt->execute();
$error = 'create tables';
throw new Exception($error);
} catch (PDOException $e) {
echo 'Create tables failed: ' . $e->getMessage();
}
echo ini_get('display_errors');