PHP Technical

Create a CSV file from MySQL with PHP

  • by Tejash Shah
  • January 14, 2011

The example code below uses the raw mysql_* functions but it should be easy enough to substitute a database library’s functions instead. It also writes the data out line by line to

PHP Technical

Sending a CSV file to the web browser with PHP

  • by Tejash Shah
  • January 14, 2011

The headers look like so, substituting filename.csv for the name you would like: header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="filename.csv"');