<?php
header('Content-Type: application/json');

try {
    $db = new PDO("sqlite:database.db");
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $db->query("SELECT user_id, name, picture, activation_date, expiry_date FROM activated_students");

    $students = [];
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $row['picture'] = $row['picture'] ? base64_encode($row['picture']) : null;
        $students[] = $row;
    }

    echo json_encode($students);
} catch (Exception $e) {
    echo json_encode(["error" => $e->getMessage()]);
}
