Import / Export MySQL Tables

Topics: Developer Forum
Sep 14, 2012 at 1:54 PM


Is there a function to import/export MySQL tables using PHPExcel.

Basically, I need to be able to use a select query, export a few tables into excel files (single file would be preferred). I am trying not to specify each column during export.

Then on another server, i would upload the file and updating the tables.

Anyone done this before?



Sep 15, 2012 at 3:48 PM

IMHO, PHPExcel isn't the right tool for this job.... Some ways : DIY,, use select into outfile for the dump(s), load data to import, if you want a GUI, use PHPMyAdmin, look for specialized script; etc.

If you really want a excel file... Well... You can use '*' in your query and mysqli_fetch_fields (or mysqli_result::fetch_fields) to have the fields name.

Using a method or another, the hard thing is to select what to import : truncate the destination table and import all ? Use a unique key with insert ignore / replace ? More complex conditions ?

Sep 15, 2012 at 5:50 PM

I'm inclined to agree with LWol... if all you want is a mechanism for backing up and restoring databases, then MySQL has better tools than writing your own using PHPExcel... try using mysqlbackup or SELECT INTO OUTFILE, which generates a csv file.

Use PHPExcel when you want formatting in a spreadsheet that you are presenting to your users, or non-text content such as images.

Sep 21, 2012 at 8:43 PM

Here is a routine that does that link