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

时间:2021-12-02 20:58:43

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".

我有一个CodeIgniter应用程序和SQL Server数据库。我正在使用PDO作为驱动程序,一切正常,但不是在我试图保存包含“select”或“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);

1 个解决方案

#1


2  

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.

这是pdo驱动程序中的一个错误...我要检查github以查看是否已修复此问题或发送拉取请求来修复它。这个问题已被解决。我建议更新你的codeigniter安装。我克隆了codeigniter repo @ github并且无法复制错误。

here is the bug: line 197 in pdo_driver.php

这是错误: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();
        }

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();
        }

#1


2  

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.

这是pdo驱动程序中的一个错误...我要检查github以查看是否已修复此问题或发送拉取请求来修复它。这个问题已被解决。我建议更新你的codeigniter安装。我克隆了codeigniter repo @ github并且无法复制错误。

here is the bug: line 197 in pdo_driver.php

这是错误: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();
        }

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();
        }