prepare($sql); $stmt->execute($params); // -- CSV Generation -- $filename = "continuum_residents_" . 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 header row fputcsv($output, [ 'ID', 'First Name', 'Last Name', 'Email', 'Phone Number', 'Date of Birth', 'Program', 'Status', 'Risk Level', 'Health Progress', 'Housing Progress', 'Employment Progress', 'Created At' ]); // Add data rows while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { fputcsv($output, [ $row['id'], $row['first_name'], $row['last_name'], $row['email'], $row['phone_number'], $row['date_of_birth'], $row['program'], $row['status'], $row['risk_level'], $row['health_progress'], $row['housing_progress'], $row['employment_progress'], $row['created_at'] ]); } fclose($output); exit;