Wednesday, February 18, 2009

Backup MySQL Data With PHP

phpSalah one programming that is widely used in the world at this time is PHP. PHP bergembang so rapidly used in the content of websites that use CMS engine. For instance is wordpress or joomla. CMS is the second most of the MySQL database. MySQL is a database that we can use for free.

This is important when we are using the MySQL data backup. Backup should we do this many times so that we keep data secure, when the hard disk damage or loss of data due to the reason we do not know. Here are any posts short, how to use a simple PHP script to make backups of data in MySQL.


  1. $dbname = "infokomtek_com";
  2. $dbhost = "localhost";
  3. $dbuser = "root";
  4. $dbpass = "******";
  5. $backupFile = "infokomtek_com";
  6. $backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
  7. $command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
  8. system($command);
  9. ?>

$ dbname = "infokomtek_com" is the name of the data base that we want to backup. $ dbhost = "localhost" is the host name data base we are. $ dbuser = "root" user to access a database. $ dbpass = "******" is the password to access the databases. Depending on your settings in MySQL, sometimes the password is not necessary to connect to MySQL.

If you save this script in crontab PHP, then you can backup your data base in accordance with yours.

No comments:

Post a Comment