Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have a CodeIgniter application and SQL Server database. I'm using PDO as a driver, everything works fine, but not when I'm trying to save data that contains 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);
like image 620
JC Sama Avatar asked Jun 28 '13 11:06

JC Sama


1 Answers

This is a bug in the pdo driver... I'm going to check github to see if this has been fixed or send a pull request to fix it. This issue has been fixed. I recommend updating your codeigniter install. I cloned the codeigniter repo @ github and was not able to replicate the error.

here is the bug: 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();
        }

here is the fix:

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();
        }
like image 115
Matt Avatar answered Nov 14 '22 22:11

Matt