php - 使用 CodeIgniter + PDO + SQL Server 包含 "select"字时数据保存两次

标签 php sql-server codeigniter pdo

我有一个 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 以查看此问题是否已修复或发送拉取请求以修复它。这个问题已被解决。我建议更新您的 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();
        }

关于php - 使用 CodeIgniter + PDO + SQL Server 包含 "select"字时数据保存两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17363241/

相关文章:

javascript - 为什么我无法选择jquery中的元素并更改内容

SQL服务器: Get total days between two dates

php - 如何使用 PHP 管理动态创建表单中的数据

php - Codeigniter 2.1 - 将 HTML 页面插入数据库

php - Codeigniter 如何处理转义输出?

php - 如何在没有 Composer 的情况下使用 PHPMailer?

jquery表的php过滤函数

sql-server - 将日期时间值设置为 SQL Server 中的变量的正确方法

php如何以字符串形式表示多级数组

sql-server - TSQL 窗口函数最佳实践