<?php
$host = "localhost";
$db = "tandddri_Student_Drivers";
$user = "tandddri_tonyramey";
$pass = "!S0ngw3av3r1!";

$conn = new mysqli($host, $user, $pass, $db);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename=export.csv');

$output = fopen("php://output", "w");

// Replace 'your_table_name' with your actual table
$result = $conn->query("SELECT * FROM your_table_name");

$first = true;
while ($row = $result->fetch_assoc()) {
    if ($first) {
        fputcsv($output, array_keys($row));
        $first = false;
    }
    fputcsv($output, $row);
}
fclose($output);
$conn->close();
?>
