Provides PHP/MySQL-based auth (sessions, CSRF), a permission-and-role system (permission groups with per-permission keys), and an admin-only user management area. Homepage left as a placeholder for later. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
32 lines
975 B
PHP
32 lines
975 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
function db(): PDO
|
|
{
|
|
static $pdo = null;
|
|
|
|
if ($pdo === null) {
|
|
$configPath = __DIR__ . '/../config.php';
|
|
if (!file_exists($configPath)) {
|
|
http_response_code(500);
|
|
exit('Konfigurationsdatei fehlt. Bitte config.example.php zu config.php kopieren und ausfuellen.');
|
|
}
|
|
|
|
$config = require $configPath;
|
|
$db = $config['db'];
|
|
$dsn = "mysql:host={$db['host']};dbname={$db['name']};charset={$db['charset']}";
|
|
|
|
try {
|
|
$pdo = new PDO($dsn, $db['user'], $db['pass'], [
|
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
|
PDO::ATTR_EMULATE_PREPARES => false,
|
|
]);
|
|
} catch (PDOException $e) {
|
|
http_response_code(500);
|
|
exit('Datenbankverbindung fehlgeschlagen. Bitte config.php pruefen.');
|
|
}
|
|
}
|
|
|
|
return $pdo;
|
|
}
|