PHP CSV export from stored MySQL Procedure
<p>Trying to use the below code to call a stored procedure on MySQL and export to CSV. It generates a csv file however it is blank. The stored procedure is called DATAEXPORT1</p>

<p>Any ideas would be grateful! </p>

<pre><code>&lt;?php


 $host = "localhost";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
$file = 'export';
$connection = mysqli_connect($host, $username, $password, $dbname) or     die("Connection Error " . mysqli_error($connection));
/*
* execute sql query
*/

$sql = "Call DATAEXPORT1()";

$result = mysqli_query($connection,$sql) or die("Selection Error " . mysqli_error($connection));

if (mysqli_num_rows($result) &gt; 0) {
while ($row = mysqli_fetch_assoc($result)) {
$csv_output .= $row['Field'].", ";
$i++;
}
}
$csv_output .= "\n";

$values = mysqli_query($connection,$sql);
while ($rowr = mysqli_fetch_row($values)) {
for ($j=0;$j&lt;$i;$j++) {
 $csv_output .= $rowr[$j].", ";
}
 $csv_output .= "\n";
 }


$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=".$filename.".csv");
print $csv_output;
mysqli_close($connection);
exit;
?&gt;
</code></pre>