2013-06-28 12 views
8

我有一個CodeIgniter應用程序和SQL Server數據庫。我使用PDO作爲驅動程序,一切工作正常,但不是當我試圖保存包含單詞「select」或「selection」的數據時。當它包含使用CodeIgniter + PDO + SQL Server的「選擇」字時保存了兩次數據

例子:

$data = array(); 
$data[] = array('title' => 'all you neeed', 'description' => 'description here'); 
$data[] = array('title' => 'try this selection', 'description' => 'description here'); 

$this->db->insert_batch($this->table, $data); 
+0

不應該'$數據[]'包含ASSOC數組,而不是數字? –

+0

是的,但這不是問題。 –

+1

你可以檢查$ this-> db-> last_query(); – devrooms

回答

2

這是PDO驅動程序中的錯誤......我要去檢查github上,看看是否已修復或發送pull請求進行修復。這個問題已被解決。我建議更新你的codeigniter安裝。我克隆了codeigniter repo @ github,但無法複製該錯誤。

這裏是錯誤:在pdo_driver.php線197

if (is_numeric(stripos($sql, 'SELECT'))) 
     { 
      $this->affect_rows = count($result_id->fetchAll()); 
      $result_id->execute(); 
     } 
     else 
     { 
      $this->affect_rows = $result_id->rowCount(); 
     } 

這裏是修復:

if (is_numeric(stripos($sql, 'SELECT')) && stripos($sql, 'SELECT') == 0) 
     { 
      $this->affect_rows = count($result_id->fetchAll()); 
      $result_id->execute(); 
     } 
     else 
     { 
      $this->affect_rows = $result_id->rowCount(); 
     } 
相關問題