gpt4 book ai didi

CakePHP updateAll() 问题

转载 作者:行者123 更新时间:2023-12-02 09:20:42 26 4
gpt4 key购买 nike

我有一个图像表,其中有一列名为type。我只是想更新所有行以将类型更改为 gallery,其中 user_id 与特定用户匹配。

我正在使用此代码

    $this->Image->updateAll(array('Image.type' => 'gallery'), 
array('Image.user_id' => $this->Auth->user('id')));

但我收到此错误:SQL 错误:1054:“字段列表”中的未知列“库”

为什么将画廊添加到字段列表中?
语法不是应该将类型设置为画廊吗?

谢谢!

最佳答案

the manual 上找到此内容:

The $fields array accepts SQL expressions. Literal values should be quoted manually.

因此,以下内容应该有效:

$this->Image->updateAll(
array('Image.type' => "'gallery'"),
array('Image.user_id' => $this->Auth->user('id'))
);

关于CakePHP updateAll() 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6988160/

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