dsjmrpym220113739 2016-05-12 13:46
浏览 22
已采纳

Codeigniter使用增量更新mysql数据

I want to add 1 to my column named SIZE (integer), this is my query:

$this->dbsections->update('sections', "SIZE = SIZE + 1");

But in the error message, it reads as:

UPDATE `sections` SET `SIZE = SIZE +` 1 = '' WHERE `NAME` = 'ABC'
  • 写回答

2条回答 默认 最新

  • dpmpa26468 2016-05-12 13:51
    关注

    You can rewrite your update query

    $this->dbsections->set('SIZE', 'SIZE+1', FALSE);// third parameter FALSE
    $this->dbsections->where('NAME', "ABC");
    $this->dbsections->update('sections');
    

    set() will also accept an optional third parameter ($escape), that will prevent data from being escaped if set to FALSE

    Read https://www.codeigniter.com/userguide3/database/query_builder.html#updating-data

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 前后端分离的学习疑问?
  • ¥15 stata实证代码答疑
  • ¥15 MATLAB数据处理插值
  • ¥50 husky+jaco2实现在gazebo与rviz中联合仿真
  • ¥15 dpabi预处理报错:Error using y_ExtractROISignal (line 251)
  • ¥15 在虚拟机中配置flume,无法将slave1节点的文件采集到master节点中
  • ¥15 husky+kinova jaco2 仿真
  • ¥15 zigbee终端设备入网失败
  • ¥15 金融监管系统怎么对7+4机构进行监管的
  • ¥15 硬件IIC从模式的数据发送,中断数据的接收,不能用HAL库(按照时序图)