<span style="font-size:18px;"><?php
$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "password";
$dbdatabase = "database";
$db_restore_success = true;
$sql_file_name = "2015-11-05_10-54-54.sql";
$con = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbdatabase);
$db_selected = mysqli_select_db($con, $dbdatabase);//选择数据库
if (!$db_selected|| !$con)
{
$db_restore_success = false;
}
else
{
$sql=file_get_contents($sql_file_name); //把SQL语句以字符串读入$sql
$a=explode(";",$sql); //用explode()函数把$sql字符串以“;”分割为数组
foreach($a as $b){ //遍历数组
$c=$b.";"; //分割后是没有“;”的,因为SQL语句以“;”结束,所以在执行SQL前把它加上
$result = mysqli_query($con, $c); //执行SQL语句
$db_restore_success = $db_restore_success && $result;
}
}
if($db_restore_success)//输出恢复情况
echo '{"status":"success"}';
else
echo '{"status":"failed"}';
?>
</span>