Php Codeigniter:分号中断查询

Php Codeigniter:分号中断查询,php,codeigniter,mysql-error-1064,Php,Codeigniter,Mysql Error 1064,我有一个SQL文件,我正试图用以下方法导入到我的CodeIgniter应用程序中: public function run_backup($filename) // full extension please { // read the file in // make sure that filename is a string $filename = (string) $filename; $backup = $this

我有一个SQL文件,我正试图用以下方法导入到我的CodeIgniter应用程序中:

public function run_backup($filename) // full extension please
    {
        // read the file in
        // make sure that filename is a string
        $filename = (string) $filename;

        $backup = $this->load->file($filename, true);

        $file_array = explode(';', $backup); // explode on semicolon
        foreach($file_array as $query)
        {
           $this->db->query("SET FOREIGN_KEY_CHECKS = 0");
           $this->db->query($query);
           $this->db->query("SET FOREIGN_KEY_CHECKS = 1");
        }
}
我在sql文件执行到一半时遇到以下错误:

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Mistakes with high risk medicines are much more common than with any other medi' at line 1

INSERT INTO quiz_question_content (`quiz_question_content_id`, `quiz_question_id`, `content`, `image_path`, `type`) VALUES (247, 235, 'Mistakes with high risk medicines are much more common than with any other medicines used
我搜索了该行,发现文本字段中有一个分号:

'Mistakes with high risk medicines are much more common than with any other medicines used; hence the reason they require special safeguards' 
分号正在终止该行并创建一个格式错误的查询,因为我的方法正在基于
“;”进行拆分

我是否可以忽略这个分号?即使是转义分号也有分号
;。SQL文件相当大,用户已将未转义字符放入文本字段中

我们在谈论多少怪癖?我宁愿使用行mysql函数来完成多个请求。
例如

我们谈论的需求有多少?我宁愿使用行mysql函数来完成多个请求。
例如,分号没有错。发生此错误的数据中必须有单/双倒逗号

尝试使用mysql\u real\u escape\u string()函数转义数据。
这将对您有所帮助。

分号没有错。发生此错误的数据中必须有单/双倒逗号

尝试使用mysql\u real\u escape\u string()函数转义数据。
这将对您有所帮助。

如果您使用
\,该怎么办
尝试转义吗?我正在使用的是一个sql文件,上面的方法正在执行每一行,
mysql\u real\u escape\u string
将转义整行。。这是行不通的。你是对的,不过我确实需要在这一行中转义这一部分。完整地向我们展示INSERT查询的php声明,如果使用
\,会怎么样
尝试转义吗?我正在使用的是一个sql文件,上面的方法正在执行每一行,
mysql\u real\u escape\u string
将转义整行。。这是行不通的。你是对的,不过我确实需要在这一行中转义该部分