PHP - MySQL query to CSV export
I have a PHP script. Its a library management system. So after all the books are stored in the database i need to create multiple reports - like clicking a link which will execute the SQL command and export the result to CSV. Can anyone guide me how can we do this CSV export?