prepare("SELECT * FROM `scc24` WHERE `slug` = :slug"); $stmt->bindParam(':slug', $slug, PDO::PARAM_STR); $stmt->execute(); return $stmt->fetch(PDO::FETCH_ASSOC); } function saveToCache($filePath, $content) { if (!file_put_contents($filePath, $content)) { error_log("Failed to write cache file: $filePath"); } } if (empty($slug)) { // echo "Slug not provided!"; // exit; } $fileName = $slug . ".html"; $filePath = __DIR__ . '/notice/' . $fileName; ob_start(); $shouldCache = false; // Flag to determine if content should be cached. if (!serveStaticFile($filePath)) { try { $pdo = new PDO("mysql:host=$mariaServer;dbname=$mariaDb", $mariaUser, $mariaPass); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $content = fetchFromDatabase($slug, $pdo); if ($content && isset($content['content']) && $content['content']) { echo '

' . htmlspecialchars($content['title']) . '

' . $content['content'] . '
'; $shouldCache = true; // Mark content as cacheable. } else { echo '

Page not found (404).

Back to home
'; } } catch (PDOException $e) { echo "

Error: " . htmlspecialchars($e->getMessage()) . "

"; } } $htmlContent = ob_get_clean(); // Save to cache only if content was found. if ($shouldCache) { saveToCache($filePath, $htmlContent); } echo $htmlContent; ?>