Codeigniter:分号破解查询

问题描述 投票:1回答:2

我有一个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' 

分号正在终止该行并创建格式错误的查询,因为我的方法基于';'进行拆分

无论如何我可以忽略这个分号吗?即使是一个逃脱的分号也有一个分号&#59;。 SQL文件非常大,并且该人将未转义的字符放入文本字​​段中。

php codeigniter mysql-error-1064
2个回答
1
投票

我们在谈论几个问题?我宁愿使用行mysql函数来执行多个quires。例如http://php.net/manual/en/mysqli.multi-query.php


0
投票

分号没有错。由于发生此错误,您的数据中必须有单/双反转逗号。

尝试使用mysql_real_escape_string()函数转义数据。这会对你有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.