From c4fcaee34d2d86ca9d807460ae3d1311eadc3f58 Mon Sep 17 00:00:00 2001 From: William Date: Mon, 17 Jan 2022 11:25:34 +0100 Subject: [PATCH] Commit --- .gitignore | 1 + app/config.example.php | 14 ++++++++++++++ app/core/DBHandle.php | 10 +++++----- app/inc.php | 6 ++++++ app/view/template/header.php | 10 +++++----- 5 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 app/config.example.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b38730b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/app/config.php \ No newline at end of file diff --git a/app/config.example.php b/app/config.example.php new file mode 100644 index 0000000..bc57409 --- /dev/null +++ b/app/config.example.php @@ -0,0 +1,14 @@ + '/public', + 'database' => [ + 'name' => 'mysql', + 'args' => [ + 'host' => 'localhost', + 'database' => 'test', + 'user' => 'root', + 'password' => '', + 'charset' => 'utf8mb4', + ], + ], +]; \ No newline at end of file diff --git a/app/core/DBHandle.php b/app/core/DBHandle.php index 9607c1e..cba05b5 100644 --- a/app/core/DBHandle.php +++ b/app/core/DBHandle.php @@ -3,11 +3,11 @@ // Encapsulates a single connection to a database class DBHandle { - private string $host = '127.0.0.1'; - private string $db = 'test'; - private string $user = 'root'; - private string $pass = ''; - private string $charset = 'utf8mb4'; + private string $host = CONFIG['database']['args']['host']; + private string $db = CONFIG['database']['args']['database']; + private string $user = CONFIG['database']['args']['user']; + private string $pass = CONFIG['database']['args']['password']; + private string $charset = CONFIG['database']['args']['charset']; public object $dbh; diff --git a/app/inc.php b/app/inc.php index 2c1bfc9..0b4711e 100644 --- a/app/inc.php +++ b/app/inc.php @@ -12,6 +12,12 @@ Tread carefully */ +// Autoloader spl_autoload_register(function ($class_name) { require __DIR__ . '/core/' . $class_name . '.php'; }); + +// Define global CONFIG constant. +define("CONFIG", + require __DIR__ . '/config.php' +); \ No newline at end of file diff --git a/app/view/template/header.php b/app/view/template/header.php index 7381f3b..978348f 100644 --- a/app/view/template/header.php +++ b/app/view/template/header.php @@ -6,7 +6,7 @@ <?=htmlspecialchars($title);?> – Stafett for livet - +