<?php require_once __DIR__ . '/init.php'; header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename=products_export_' . date('Ymd_His') . '.csv'); $out = fopen('php://output', 'w'); fputcsv($out, ['id','barcode','name','production_date','expiry_date','notes','created_at']); $stmt = $pdo->query('SELECT id,barcode,name,production_date,expiry_date,notes,created_at FROM products ORDER BY id'); while($row = $stmt->fetch(PDO::FETCH_NUM)){ fputcsv($out, $row); } fclose($out); exit; ?>