次の方法で CodeIgniter アプリケーションにインポートしようとしている SQL ファイルがあります。
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 ファイルは非常に大きく、エスケープされていない文字がテキスト フィールドに配置されています。