2013-08-22 51 views
1

我有我試圖導入我用下面的方法笨應用程序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' 

分號終止行並創建一個格式錯誤的查詢,因爲我的方法正在拆分基於​​3210

是否有無論如何我可以忽略這個分號?即使是一個轉義分號也有分號 &#59; sql文件非常大,並且人員已經將非轉義字符放入文本字​​段中。對此的任何幫助將是真棒

+0

而如果你使用'\;'來嘗試並逃避它呢? –

+0

這是一個我正在使用的sql文件,上面的方法正在執行每一行,'mysql_real_escape_string'將轉義整個行..哪一個不會工作。你是對的,雖然我確實需要逃避該部分。 –

+1

向我們展示INSERT查詢的php聲明 –

回答