Created
November 28, 2012 22:26
-
-
Save SahilC/4165155 to your computer and use it in GitHub Desktop.
Php Mysql Database backup and restore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dump_path = ""; //input location for the backup to be saved | |
$host = ""; //db host e.g.- localhost | |
$user = ""; //user e.g.-root | |
$pass = ""; //password | |
$command=$dump_path.'mysqldump -h '.$host.' -u '.$user.' bank > bank.sql'; | |
system($command); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dump_path = ""; //your backup location | |
$host = ""; //host | |
$user = ""; //username | |
$pass = ""; /passwprd | |
$command=$dump_path.'mysql -h '.$host.' -u '.$user.' bank < bank.sql'; | |
system($command); | |
?> |
@sagar03d try this in the restore.php file.
$tempConfig = tmpfile();
fwrite($tempConfig, "[client]\nhost={$host}\nuser={$user}\npassword={$pass}");
$tempConfigPath = stream_get_meta_data($tempConfig)['uri'];
system("mysql --defaults-extra-file={$tempConfigPath} bank < bank.sql');
hello ... the Backup.php returns an empty file ?? what is the problem (Testing on localhost wampserver)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Restore not working, since 'mysql -h '.$host.' -u '.$user.' bank < bank.sql' command asking for password when entered in command prompt