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;
}
}