Export/Backup database to a file

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Export/Backup database to a file

Post 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.
User avatar
haagen
Forum Commoner
Posts: 79
Joined: Thu Jul 11, 2002 3:57 pm
Location: Sweden, Lund

Post 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
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post by fastfingertips »

I understood this part, but do you have an example for me? A cod example?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
Post Reply