Flesh out database code

master
Skylar Ittner 6 years ago
parent 8c55d0ca2c
commit 02349ab970

1
.gitignore vendored

@ -1 +1,2 @@
*settings.php
*.bak

Binary file not shown.

@ -9,6 +9,16 @@
*/
ob_start(); // allow sending headers after content
// Settings file
require __DIR__ . '/settings.php';
if (!DEBUG) {
error_reporting(0);
} else {
error_reporting(E_ALL);
ini_set('display_errors', 'On');
}
// Set default content type to JSON
header('Content-Type: application/json; charset=utf-8');
@ -37,15 +47,10 @@ if (!file_exists(__DIR__ . '/vendor/autoload.php')) {
}
require __DIR__ . '/vendor/autoload.php';
// Settings file
require __DIR__ . '/settings.php';
function sendError($error) {
die('{"status": "ERROR", "msg": "A fatal application error has occurred: ' . htmlspecialchars($error) . '"}');
}
date_default_timezone_set(TIMEZONE);
// Database settings
// Also inits database and stuff
use Medoo\Medoo;
@ -57,20 +62,18 @@ try {
'database_file' => DB_FILE,
'charset' => DB_CHARSET
]);
$database_configured = $database->query("SELECT name FROM sqlite_master WHERE type='table' AND name='accounts';")->fetchAll();
if (count($database_configured) == 0) {
$database->query("CREATE TABLE IF NOT EXISTS `accounts` "
. "(`uid` INT NOT NULL UNIQUE PRIMARY KEY, `username` VARCHAR(190) NOT NULL, "
. "`password` VARCHAR(255) NOT NULL, `authsecret` VARCHAR(100))");
}
} catch (Exception $ex) {
header('HTTP/1.1 500 Internal Server Error');
sendError("Database error. $ex");
}
if (!DEBUG) {
error_reporting(0);
} else {
error_reporting(E_ALL);
ini_set('display_errors', 'On');
}
$VARS;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$VARS = $_POST;

Loading…
Cancel
Save