fputcsv返回double值

时间:2014-07-11 07:16:12

标签: php fputcsv

所以目前我正在尝试创建一个数据库导出脚本,我得到的是:

<?php
   $con = mysqli_connect("SERVER","USER","PASSWORD","DATABASE");
   $query = mysqli_query($con,"SELECT * FROM `TABLE`;");
   unlink('testfile.csv');
   $fp = fopen("testfile.csv","w");
   fputcsv($fp,array("Col1","Col2","Col3"),";");
   while ($list = mysqli_fetch_array($query)){
     fputcsv($fp,$list,";");
  }
  fclose($fp);
?>

这似乎返回"Col1 Col1 Col2 Col2 Col3 Col3"

虽然fputcsv($fp,array($list[0],$list[1],$list[2]),";");似乎工作正常。 有没有办法避免这个解决方案并通过Original $ list数组来完成?

1 个答案:

答案 0 :(得分:0)

尝试:

$list = mysqli_fetch_array($query, MYSQLI_NUM);

这应该将数组作为数字数组返回,而不是默认为混合映射。在输出上尝试print_r,以确保它符合您的期望。

http://uk3.php.net/manual/en/mysqli-result.fetch-array.php