Initial habit tracker project

This commit is contained in:
2026-07-10 16:18:31 +02:00
commit 23416ee382
20 changed files with 1157 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
use PDO;
use PDOException;
class Database
{
private static ?PDO $connection = null;
public static function connection(): PDO
{
if (self::$connection !== null) {
return self::$connection;
}
$db = config('database');
$dsn = sprintf(
'mysql:host=%s;dbname=%s;charset=%s',
$db['host'],
$db['dbname'],
$db['charset']
);
try {
self::$connection = new PDO($dsn, $db['user'], $db['password'], [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (PDOException $exception) {
throw new PDOException('Datenbankverbindung fehlgeschlagen.');
}
return self::$connection;
}
}
+15
View File
@@ -0,0 +1,15 @@
<?php
class View
{
public static function render(string $view, array $data = []): void
{
extract($data, EXTR_SKIP);
$viewPath = __DIR__ . '/../Views/' . $view . '.php';
require __DIR__ . '/../Views/layout/header.php';
require $viewPath;
require __DIR__ . '/../Views/layout/footer.php';
}
}