0

我有一个备份 wordpress 数据库的脚本,效果很好。但是,我试图用 php 恢复它,它总是在回车处停止,并且出错。错误:

\n\n这是一个文本示例,第 1 行的 chang'

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 '\n\n 附近使用的正确语法

我试过了 nl2br,,,,甚至他们。htmlspecialcharsmysql_real_escape_stringpreg-replacing

这是我正在使用的代码:

// Connect to MySQL server
mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to MySQL server: ' . mysql_error());
// Select database
mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines = file($filename, FILE_IGNORE_NEW_LINES);
// 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(mysql_error() . '<br /><br />');
        // Reset temp variable to empty
        $templine = '';
       }
}

$filename变量是一个.sql格式正确的文件。在数据库转储中,我可以看到\n's,并且我很确定wordpress做了某种nl2br,并将它们替换为<p>'s,因此可以删除它们或完全删除站点上的间距。

4

0 回答 0