36293-vm/export.php
2025-11-25 21:05:38 +00:00

34 lines
743 B
PHP

<?php
// --- DATABASE CONNECTION ---
require_once __DIR__ . '/db/config.php';
try {
$pdo = db();
$stmt = $pdo->query("SELECT * FROM roster ORDER BY fullNameEn");
$roster_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
// --- CSV EXPORT ---
$filename = "roster_export_" . date('Y-m-d') . ".csv";
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="' . $filename . '"');
$output = fopen('php://output', 'w');
// Add headers
if (!empty($roster_data)) {
fputcsv($output, array_keys($roster_data[0]));
}
// Add data
foreach ($roster_data as $row) {
fputcsv($output, $row);
}
fclose($output);
exit();