Reputation: 1002
I am currently working on a project that requires an automated export of a CSV file from mySQL. I am using Cpanel with phpMyAdmin.
This is not an export of the entire database so I am unable to simply set a CRON task to do a mySQLDump. I have a procedure in place that links together the tables I need and a way to run that procedure as a scheduled task, but I now need a way to actually export the CSV with the data in that procedure creates and save the CSV file on the server.
Any ideas how to do this please?
Upvotes: 2
Views: 3731
Reputation: 94
I think you will need to write a script to do the custom export.
If you are familiar with PHP, you can use the MySQLi library to connect to the database: http://php.net/manual/en/book.mysqli.php
Once you have the rows to export, you can write them to a CSV file using: http://php.net/manual/en/function.fputcsv.php
Finally, setup a cron to run the script as frequently as needed.
For example:
* * * * * /usr/bin/php my_export_script.php
Upvotes: 2