列名称不会导出到csv中,但数据会导出

时间:2020-03-27 14:52:38

标签: mysql pdo

以下代码中的所有内容似乎都可以正常工作,因为它确实从表中下载了数据,但是列名称未在csv中显示是什么问题?

$stmt = $db->prepare("select * from interviews");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);

$filename = "export.csv";

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

header('Content-Type: text/csv');

header('Content-Disposition: attachement; filename="export.csv"');

header("Pragma: no-cache");

header("Expires: 0");

foreach ($rows as $line) { 
    fputcsv($f, $line); 
}

fclose($f);

谢谢

0 个答案:

没有答案