简体   繁体   中英

Restoring a Mysql Database with PHP?

What i do with this code is: I ask the user to select a backup to restore(Check) When the user hit the "Submit" button moves the file to a local carpet of the server(Check) I call the System function to call mysql.exe to restore the sql file that is in the local server(Problem here)

<?php

if($_FILES['enviar']){
$file_name="Respaldo.sql";
move_uploaded_file($_FILE['enviar']['tmp_name'],"Backups/$file_name");
$batche=system("C:/WAMP/BIN/MYSQL/MYSQL5.5.24/bin/mysql.exe -u root test < C:/WAMP/WWW/Backups/respaldo.sql");
echo $batche;

}
?>

If i copy exactly this "C:/WAMP/BIN/MYSQL/MYSQL5.5.24/bin/mysql.exe -u root test < C:/WAMP/WWW/Backups/respaldo.sql" into a windows shell it restores the backup without any problem, Any help?.. Thanks

----EDIT---

The problem is that when I call the system function it doesn't do the restoring task, the DB remains Empty.

$batche=system("C:/WAMP/BIN/MYSQL/MYSQL5.5.24/bin/mysql.exe -u root test < C:/WAMP/WWW/Backups/respaldo.sql");

代替上面的代码,您将如下所示替换:

$batche=**shell_exec** ("C:/WAMP/BIN/MYSQL/MYSQL5.5.24/bin/mysql.exe -u root test < C:/WAMP/WWW/Backups/respaldo.sql");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM