使用 update_batch 增加数据库中的字段自动添加单引号 调用函数代码
$this->db->update_batch("FundCategory",$create_data,'fundCategoryId')
我的 codigniter 最后一个查询是
UPDATE `FundCategory` SET `fundCategoryUpdatedById` = CASE
WHEN `fundCategoryId` = '4' THEN '20000045'
WHEN `fundCategoryId` = '4' THEN '20000045'
ELSE `fundCategoryUpdatedById` END, `fundCategoryValue` = CASE
WHEN `fundCategoryId` = '4' THEN 'fundCategoryValue + 100'
WHEN `fundCategoryId` = '4' THEN 'fundCategoryValue + 200'
ELSE `fundCategoryValue` END
WHERE `fundCategoryId` IN('4','4')
我想在增加“fundCategoryValue”列之后删除单引号
最佳答案
通过修改核心试试这个
https://github.com/bcit-ci/CodeIgniter/blob/develop/system/database/DB_query_builder.php#L2019
功能
public function set_update_batch($key, $index = '', $escape = NULL)
{
..
..
..
}
来自
'value'=>($escape === FALSE ? $v2 : $this->escape($v2))
给
'value'=>(is_array($v2) ? $v2[0] : ($escape === FALSE ? $v2 : $this->escape($v2)))
并像下面这样输入
$data = array(
array(
'fundCategoryId' => '3' ,
'fundCategoryValue' => '500' , // generates with single quotes
),
array(
'fundCategoryId' => '4' ,
'fundCategoryValue' => array('fundCategoryValue + 100') // generates without single quotes
)
);
在旧的 CI 2.2.x 上
修改DB_active_rec.php
来自
if ($escape === FALSE)
{
$clean[$this->_protect_identifiers($k2)] = $v2;
}
else
{
$clean[$this->_protect_identifiers($k2)] = $this->escape($v2);
}
给
$clean[$this->_protect_identifiers($k2)] = (is_array($v2)? $v2[0] : ( ($escape === FALSE) ? $v2 : $this->escape($v2) ));
关于php - 使用 update_batch 增加数据库中的字段 自动添加单引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41889143/