I'm trying to query a remote MYSQL server via PHP and retreive a pretty large record set which I then need to write out to a file. My problem is that the query, or more likely, the writing to a file seems to just die. Below is my code, but I'm oretty sure there must be a better way to do this!?! I'm trying to return 100K rows!
//the query
$result = mysql_query("SELECT 1,2,3,4,5 FROM product");
while($row = mysql_fetch_array($result)) {
$csv_output .= "$row[1]\t$row[2]\t$row[3]\t$row[4]\t$row[5]\n";
$csv_output .= "\015\012";
//write out the results to a file
$handle=fopen($filename, 'w+');
fwrite($handle, $csv_output);
fclose($handle);
}
Thanks.