Page 1 of 1
Export/Backup database to a file
Posted: Wed Mar 17, 2004 4:27 am
by fastfingertips
Does anyone has the code of exporting the database structure and information to a file?
My problem, is that the file must be downloaded over internet. So when a user is clicking on the "Back-up" button the "Save to" window must appear.
I've tried to take a look in the php admin but i couldn't understand that.
Posted: Wed Mar 17, 2004 5:47 am
by haagen
Hi there
If your database isn't to complex you could dump data into a file which you throw at the user (webclient). How to redirect a SELECT query into a file is described in the MySQL manual:
http://www.mysql.com/doc/en/SELECT.html
Posted: Wed Mar 17, 2004 6:04 am
by fastfingertips
I understood this part, but do you have an example for me? A cod example?
Posted: Wed Mar 17, 2004 8:45 am
by JAM
Run something similiar to this:
Code: Select all
SELECT a,b,a+b INTO OUTFILE 'result.txt'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM yourtable;
...and after the query is done, you could simply
Code: Select all
header("Location: http://www.example.com/result.txt");
Lookup header() in the php manual, and look at the user comments to find out how you could initiate downloads directly using it.
Just ideas.