gpt4 book ai didi

sql - 使用数据库字段值与 cakephp 中的保存字段相加

转载 作者:行者123 更新时间:2023-12-04 14:29:34 25 4
gpt4 key购买 nike

我的问题很简单,但很难为搜索引擎找到答案。

我只想更新数据库中的一个字段,使用该字段的旧值添加另一个值。我目前正在使用以下内容:

$this->Advertisement->saveField('total_views', '(total_views + 1)', false);

但这给了我下一个查询:
UPDATE `advertisement` SET `total_views` = '(total_views +1)', `modified` = '2011-08-26 10:44:58' WHERE `advertisement`.`id` = 16

这是错误的,应该是:
UPDATE `advertisement` SET `total_views` = (total_views +1), `modified` = '2011-08-26 10:44:58' WHERE `advertisement`.`id` = 16

问题在于它放在哪里 (total_views +1)引号之间。

有没有人知道如何让这个工作?

最佳答案

$this->Advertisement->updateAll(
array('Advertisement.total_views' => 'Advertisement.total_views + 1'),
array('Advertisement.id' => 1)
);

关于sql - 使用数据库字段值与 cakephp 中的保存字段相加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7202256/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com