<?php
require_once('shikanisha.kts.php'); // Ensure the database connection file is properly included

header("Content-Type: application/json");

try {
    $query = "SELECT id, session_name FROM sessions ORDER BY id DESC";
    $result = $conn->query($query);

    if (!$result) {
        throw new Exception("Error fetching sessions: " . $conn->error);
    }

    $sessions = [];
    while ($row = $result->fetch_assoc()) {
        $sessions[] = $row;
    }

    echo json_encode(["success" => true, "sessions" => $sessions]);
} catch (Exception $e) {
    echo json_encode(["success" => false, "message" => $e->getMessage()]);
} finally {
    $conn->close();
}
?>
