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 - +