You can do this a number of ways using PHP...
Look at fwrite
[example]...
$f = fopen('/tmp/data.csv', 'a'); //<< in 'a' append mode
fwrite($f, 'line of data 1'); //<< you will have to loop through this line
fclose($f); // close handle
Or using a MYSQL query...
[example]...
SELECT field1,field2,field3
FROM table
INTO OUTFILE '/tmp/data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'