PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]); } catch (PDOException $e) { http_response_code(500); die('Database connection failed: ' . htmlspecialchars($e->getMessage())); } } return $pdo; } /** Get a config value from the admin config file. */ function cfg(string $key, $default = null) { static $cfg = null; if ($cfg === null) { $cfg = require __DIR__ . '/config.php'; } return $cfg[$key] ?? $default; }