What a waste...
for ($r=0; $r < $row; $r++) {
$rows[$r] = array($a, $b); // build an array of arrays...
}
foreach($rows as $details) {
fputcsv($file, $details); // use the array directly
}
There is ZERO point in building a string from distinct bits of data, just to explode that single string back into distinct bits of data later on.
As far as the rest of the code goes, if you're intending to download that csv to the client browser, you never actually output the csv once it's built. You'd need
...
fclose($file);
readfile($file); // dump to client