I'm getting a warning
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, array given
when trying to export a MySQL query result as CSV using PHP code like this:
public static function exportLocationCSV($id){
$sql =<<<EOF
SELECT col1, col2, col3
FROM table1
JOIN table2 ON table1.col0=table2.col0
WHERE table1.col0 = $id;
EOF;
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));
$query_export= self::$db_connection->query($sql);
$rows = array();
while($r = mysqli_fetch_assoc($query_export)){
$rows[] = $r;
}
// loop over the rows, outputting them
while ($row = mysql_fetch_assoc($rows)) fputcsv($output, $row);
}
self::$db_connection->query()function look like? Is it a custom function that you created ?var_dump($query_export)to see what you get.