为什么我的CSV输出包含每列两次?

cro*_*don 0 php csv

我有以下内容:

$name = 'registrations.csv';
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename='. $name);
header('Pragma: no-cache');
header("Expires: 0");
$outstream = fopen("php://output", "w");
$results = mysql_query("select * from registrations");
while( $result = mysql_fetch_array($results) )
{
  fputcsv($outstream, $result);
}
fclose($outstream);
Run Code Online (Sandbox Code Playgroud)

这很好用,除了它给出了每列中的两列.例如,我在表中有一个given_name列和一个surname列.生成的csv文件显示每列两次.为什么?

Joh*_*nde 6

更改mysql_fetch_array()mysql_fetch_assoc().mysql_fetch_array()获取数据库结果的数字和关联数组.

while( $result = mysql_fetch_assoc$results) )
{
  fputcsv($outstream, $result);
}
Run Code Online (Sandbox Code Playgroud)