prepare("SELECT * FROM seasons WHERE is_current = 1 LIMIT 1"); $stmt->execute(); $season = $stmt->fetch(); if ($season) { return $season; } // 2. Versuch: Letzte Saison nach ID $stmt = $db->prepare("SELECT * FROM seasons ORDER BY id DESC LIMIT 1"); $stmt->execute(); // Gibt die gefundene Saison oder `false` zurück. Die Funktion endet hier, wenn die Abfrage erfolgreich war. return $stmt->fetch(); } catch (\PDOException $e) { // Fallback: Wird ausgeführt, wenn die 'seasons'-Tabelle nicht existiert. // Wir ermitteln die höchste season_id aus der 'rounds'-Tabelle. $stmt = $db->prepare("SELECT season_id FROM rounds ORDER BY season_id DESC LIMIT 1"); $stmt->execute(); $row = $stmt->fetch(); if ($row) { // Erstelle ein "Dummy" Season-Objekt für die Kompatibilität return [ 'id' => $row['season_id'], 'name' => 'Saison ' . $row['season_id'] ]; } } // Wird erreicht, wenn 'seasons' nicht existiert und auch keine Runden gefunden wurden. return null; } }