问题
Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
I can't solve a problem occuring when I try to export an array to a csv file. I have used this function several tumes without problem but here I do not see where my mistake is.
I set an array :
$mytags= array();
I populate it by a loop. When I print the content through print_r($mytags);
it seems to be ok, here some examples of my output:
Array ( [0] => [1] => air-travel [2] => airports [3] => security-airport [4] => city-airport ... )
After that I try to export the result to csv by fputcsv:
$fp = fopen('file.csv', 'w');
foreach ($mytags as $fields) {
fputcsv($fp, $fields);
}
But I get this error :
Warning: fputcsv() expects parameter 2 to be array, string given in C:\wamp\www\tests\capturetags.php on line 55
Could the problem be that there is only one field ?
Alternatively, I tried to replace $fields by $mytags to write the csv, and in this case I get a 4GB files, so it's not the
Does someone see how to record thhis unique field in a csv file ?
回答1:
The error is very clear, $fields is not an array, it is a string. You need an array.
fputcsv($fp, $mytags);
Without a foreach loop will do the job.
来源:https://stackoverflow.com/questions/11580702/export-an-array-to-csv-failure-string-given