<?php
// Connect to SQLite database
$db = new PDO('sqlite:database.db');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Delete expired users EXCEPT if user_id = '0'
$delete_stmt = $db->prepare('
    DELETE FROM activated_students 
    WHERE expiry_date <= datetime("now") 
    AND user_id != "0"
');

// Execute the delete statement and get the number of affected rows
$delete_stmt->execute();
$deleted_users = $delete_stmt->rowCount(); // Get the number of rows deleted

echo "$deleted_users expired users deleted.";
