Using PHP To Backup MySQL Database
There are at least three ways to backup your MySQL Database :
|
Execute a database backup query from PHP fileBelow is an example of using SELECT INTO OUTFILE query for creating table backup :
<?php $tableName = 'mypet'; include 'closedb.php'; ?> To restore the backup you just need to run LOAD DATA INFILE query like this :
<?php $tableName = 'mypet'; include 'closedb.php'; ?> It's a good idea to name the backup file as tablename.sql so you'll know from which table the backup file is |
Run mysqldump using system() functionThe system() function is used to execute an external program. Because MySQL already have built in tool for creating MySQL database backup (mysqldump) let's use it from our PHP script
<?php $backupFile = $dbname . date("Y-m-d-H-i-s")
. '.gz'; ?> |
Use phpMyAdmin to do the backupThis option as you may guessed doesn't involve any programming on your part. However I think i mention it anyway so you know more options to backup your database. To backup your MySQL database using phpMyAdmin click on the "export" link on phpMyAdmin main page. Choose the database you wish to backup, check the appropriate SQL options and enter the name for the backup file.
|
|
|
MySQL Update and Delete | PHP MySQL Tutorial : Backup MySQL Database | Form Validation With PHP |
|
| This tutorial is far from perfect so if you have any critiques, questions, comments or problems about this tutorial please tell me. Click here to send your feedback. And if you like this tutorial please link to this site. It will really help a lot :-) |
Copyright © 2004 - 2008 www.php-mysql-tutorial.com | Privacy Policy