Question: how to export data from database to csv file in php?
Answer: Retrieve data from the MySQL database. Create a file pointer using fopen() function. Specify the header columns and put into the CSV file. Output each row of the data, format line as CSV and write to file pointer.