恢复MySQL数据库会出现错误 [英] Restoring mysql database gives errors
本文介绍了恢复MySQL数据库会出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试使用 http中的以下代码还原数据库://www.a2zwebhelp.com/php-script-to-import-mysql-database 但是我收到错误:查询为空" 我要去哪里错了?
I am trying to restore a database using the following code from http://www.a2zwebhelp.com/php-script-to-import-mysql-database But i am receiving "Error: Query was empty" Where am i going wrong?
P.s.从phpmyadmin导入sql文件可以达到目的,但不能使用此功能.
P.s. importing the sql file from phpmyadmin serves the purpose but doesnt work using this.
<?php
include 'connect.php';
$filename = 'DB_Backups/db-backup-08-04-14-08-39-16.sql';
$templine = '';
$lines = file($filename); //Read entire file
foreach($lines as $line){
if(substr($line, 0, 2) == '--' || $line == '') //Skip all comments
$templine.=$line;
if(substr(trim($line), -1, 1) == ';'){
mysql_query($templine) or print('Error: '.mysql_error().'<br>');
$templine = '';
}
}
?>
推荐答案
稍有改进,便可以使用:) @最喜欢的东西,谢谢你的提示.
A slight improvement and it works :) @ favoretti thank you for the hint.
<?php
// Name of the file
$filename = 'DB_Backups/'.$name;
// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename);
// Loop through each line
foreach ($lines as $line)
{
// Skip it if it's a comment
if (substr($line, 0, 2) == '--' || $line == '')
continue;
// Add this line to the current segment
$templine .= $line;
// If it has a semicolon at the end, it's the end of the query
if (substr(trim($line), -1, 1) == ';')
{
// Perform the query
mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' . mysql_error() . '<br /><br />');
// Reset temp variable to empty
$templine = '';
}
}
?>
这篇关于恢复MySQL数据库会出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文