mdibb.net

MySQL2CSV – simple online database dumps to CSV using PHP

I've often had the need to quickly and easily take a copy of a database table. Sometimes I am making a backup, other times I just want the data in CSV (Comma Separated Value) format so I can easily import it into another database or programme and so on.



There are ways to do this with various things like web-based MySQL tools, or using the command line directly but sometimes nothing is quicker than a simple FTP client! So I put together this simple PHP script that will access a table and dump all of its rows and show me the CSV in a text box, or just let me save off the entire page for use later. This could be used as a really simple backup script for a database by using a combination of cron and wget to take a quick copy without any human intervention!

Click below to view some example output. Feel free to take and use this script as you please – please note that it is just a quick and dirty little script I knocked up, there is no warranty and I cant vouch for its fitness for a particular purpose.

Download MySQL2CSV - View Example output

MySQL2CSV Usage Instructions


To use this script, all you need to do is edit the first few lines of the PHP file to reflect your database settings. The lines you need to look at are the ones that look a bit like these:

$Settings['dbusername'] = "username"; $Settings['dbpassword'] = "password"; $Settings['dbhost'] = "localhost"; $Settings['dbport'] = "3306"; $Settings['dbname'] = "databasename"; $Settings['dbtable'] = "tablename";

Once you have provided the correct details for the script, all you then need to do is upload the file to your server and then view the page from there.

Back 23.08.2006.

where csv !

> nitin > 21.06.2007

Click on the "View Example output" link to see the example CSV output

> Matt > 21.06.2007

dss

> sds > 21.06.2007

Hi

Looks good! Very useful, good stuff. Good resources here. Thanks much!

Bye





> govokinolij > 10.07.2007