0
我想通過php使用select語句導出一個空字段的csv文件,但空列沒有被包含在csv輸出中。插入空列到csv問題 - php
$query = "SELECT client_last_name,'','','','', client_first_name FROM billing_line_item";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Query Failed" . mysqli_error($connection));
} else {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen('php://output', 'w');
fputs($output, implode($header1, ',')."\n");
while ($row = mysqli_fetch_assoc($result)) {
fputs($output,implode($row, ',')."\n");
}
fclose($output);
exit();
}
在我的csv文件輸出如下:
Print_R of Array:
Array
(
[client_last_name] => LastName
[] =>
[client_first_name] => FirstName
)
Output: LastName,,FirstName
Expecting: LastName,,,,,FirstName