当数据包含“;选择“;使用CodeIgniter+PDO+SQL Server


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

我有一个CodeIgniter应用程序和SQL Server数据库。我使用PDO作为驱动程序,一切都很好,但当我试图保存包含单词"select"或"selection"的数据时就不行了。

示例:

$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);

这是pdo驱动程序中的一个错误。。。我将检查github,看看这个问题是否已经修复,或者发送一个pull请求来修复它。这个问题已经修复。我建议更新你的代码点火器安装。我克隆了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();
        }