Data is saved twice when it contains the word "select" using CodeIgniter + PDO + SQL Server

I have a CodeIgniter application and a SQL Server database. I use PDO as a driver, everything works fine, but not when I try to save data containing the words "select" or "selection".

Example:

$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); 
+8
php sql-server pdo codeigniter
source share
1 answer

This is a bug in the pdo driver ... I'm going to check github to make sure it is fixed or send a transfer request to fix it. This issue has been fixed. I recommend updating the codeigniter installation. I cloned the codeigniter @github repository and could not replicate the error.

here is the error: line 197 in pdo_driver.php

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

there is a fix here:

 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(); } 
+2
source share

All Articles