views:

26

answers:

1

Hi there,

I need to export data from mysql to a csv file with column heading but i dont have file permission on the server. Is there any otherway to do it? i.e. using php fwrite? or fputcsv?

Any help will be much appriciate.

Thanks.

+1  A: 

If you can connect to the MySQL server, you can run the mysqldump utility, which is capable of generating CSV files. This is far easier than trying to come up with something yourself.

mysqldump --tab --fields-terminated-by="," --host=$SERVER --user=$USERNAME --password=$PASSWORD $DATABASE
Michael Mior
Thank you for quick response mr Michael Mior where it will save the file? Is there a way to specify a file name for output?
Kamar Khan
The file will get written to standard output. If you want to save to a file, just redirect by adding ` > filename` to the end.
Michael Mior