How to backup data in the database?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nettolan
Forum Newbie
Posts: 1
Joined: Thu Jan 20, 2011 12:31 pm

How to backup data in the database?

Post by nettolan »

Hi people!

Just recently got into coding and i'm a total idiot in it. I got no idea how to backup data in the database.

Anyone have any PHP script which i can use to backup data in the database?

After backing up, how do i restore using PHP codes?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: How to backup data in the database?

Post by John Cartwright »

There are a million tutorials that can do this.

Basically it comes down to running the following query, which basically just dumps the contents of the table into a file.

SELECT * INTO OUTFILE 'your_backup_file.sql' FROM `your_table_name`

Creating a PHP script to run this, then configure a cron job to run the PHP script at whatever interval.

Then to load it

LOAD DATA INFILE 'your_backup_file.sql' INTO TABLE `your_table_name`

And finally, for my favorite resource which will answer your question in extreme detail - http://lmgtfy.com/?q=PHP+MySQL+backup
Post Reply