I want to copy files from a database into a file .csv. Is use this code
$whatday=\Carbon\Carbon::today()->toDateString();
$file = fopen('/var/www/laravel/public/'.$whatday.'.csv', 'w');
fwrite($file, '[OPTION1];[OPTION2]'.PHP_EOL);
$data=\App\Status::all();
foreach($data as $dt)
{
$col1= $dt->opt1;
$col2= $dt->opt2;
fwrite($file,
$col1.';'.
$col2.';'
.PHP_EOL);
}
}
fclose($file);
If the rows in database are few I don't have problems (takes a few seconds), but if the rows are many(>10000, I work with this volumes of data) the copy of the rows takes 1 hour more or less. My question is: Are There other functions faster ? Sorry for my english!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire