如何使用codeigniter的update_batch()

问题描述 投票:0回答:1

使用CI

update_batch()
,我无法在增加整数数据库值的地方设置值。 这与CI
set(); update()
成功合作,但是由于有多个更新,因此Batch是更好的选择。 我的列有名称末尾具有相同字符的列,在开始时具有不同的字符(不同年份):2014x,2015x,2016x,等等。 因此,我创建了一个标识这一年的

$var

,然后通过串联添加字符串

'x' and 'y'
。 最后,数组中的值设置是增量1,因此我添加+1。 此串联在键中正常工作 - 也就是说,我正在更新正确的列和字段。
$data = array(
    array('name' => $name1,
            $var.'x' => $var.'x+1'),
    array('name' => $name2,
            $var.'y' => $var.'y+1')
            );          
$this->db->update_batch('my_table', $data, 'tname');

在上述情况下,该字段的更新仅为已定义的一年的值。

我还尝试了以下内容:

$var

我如何使用

=> '{"$var.x+1"}' // places a '0' value in the field => $var.'x' +1 // places the value of $var => '$var.x+1' // places a '0' value in the field

来递增我的字段

update_batch()
作为一个示例,此代码成功工作:

1
	
您无法通过update_batch进行此操作。

在文档中

https://ellislab.com/codeigniter/user-guide/database/active_record.html

,这是这样的:

  
php mysql arrays codeigniter sql-update
1个回答
2
投票

如何重复DB->设置?例如

$this->db->where('name',$name1); $this->db->set($var.'x',$var.'x+1',FALSE); $this->db->update('my_table');

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.