Backup and Restore MySQL database in PHP -
i trying use php backup , restore mysql database:
backup:
$dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'dbpass'; $dbname = 'test'; $output = "d:/backup/test.sql"; exec("d:/xampp/mysql/bin/mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname > $output"); echo "backup complete!";
restore:
$dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'dbpass'; $dbname = 'test'; $output = "d:/restore/test.sql"; exec("d:/xampp/mysql/bin/mysql --opt -h $dbhost -u $dbuser -p $dbpass $dbname < $output"); echo "restore complete!";
but both not working. when backup complete check test.sql
file blank. when restore complete, database still blank.
how can fix this?
script backup using php
<?php define("backup_path", "/home/abdul/"); $server_name = "localhost"; $username = "root"; $password = "root"; $database_name = "world_copy"; $date_string = date("ymd"); $cmd = "mysqldump --routines -h {$server_name} -u {$username} -p{$password} {$database_name} > " . backup_path . "{$date_string}_{$database_name}.sql"; exec($cmd); ?>
script restore
<?php $restore_file = "/home/abdul/20140306_world_copy.sql"; $server_name = "localhost"; $username = "root"; $password = "root"; $database_name = "test_world_copy"; $cmd = "mysql -h {$server_name} -u {$username} -p{$password} {$database_name} < $restore_file"; exec($cmd); ?>
Comments
Post a Comment