exec($sql); } function generate_reg_code(): string { return 'REG-' . date('Ymd') . '-' . strtoupper(bin2hex(random_bytes(3))); } function insert_registration(array $data): int { $stmt = db()->prepare( "INSERT INTO registrations (reg_code, name, education, major, photo_path) VALUES (:reg_code, :name, :education, :major, :photo_path)" ); $stmt->bindValue(':reg_code', $data['reg_code']); $stmt->bindValue(':name', $data['name']); $stmt->bindValue(':education', $data['education']); $stmt->bindValue(':major', $data['major']); $stmt->bindValue(':photo_path', $data['photo_path']); $stmt->execute(); return (int)db()->lastInsertId(); } function fetch_registrations(): array { $stmt = db()->query("SELECT * FROM registrations ORDER BY created_at DESC"); return $stmt->fetchAll(); } function fetch_registration(int $id): ?array { $stmt = db()->prepare("SELECT * FROM registrations WHERE id = :id"); $stmt->bindValue(':id', $id, PDO::PARAM_INT); $stmt->execute(); $row = $stmt->fetch(); return $row ?: null; }