我有一个 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 文件非常大,并且该人已将未转义的字符放入文本字段中。