gpt4 book ai didi

php - 原始查询 - 更新多列 - 不适用于 Idiorm

转载 作者:行者123 更新时间:2023-11-30 22:42:42 25 4
gpt4 key购买 nike

我正在使用 Idiorm - 一个非常简单的 ORM。我正在尝试在单个查询中更新多行。 Idiorm 不支持这个,所以我只剩下 n 查询或 raw_query陈述。

我选择后者。

但是,我似乎无法让它发挥作用。他们查询本身并不是很复杂:

UPDATE products 
SET discount_green = some_value
WHERE category_id = some_other_value
AND discount_green != yet_another_value
AND has_double_discount != 1

在 Idiorm 语法中它看起来像这样:

ORM::for_table('products')
->raw_query(
"UPDATE products
SET discount_green = :some_value
WHERE category_id = :some_other_value
AND discount_green != :yet_another_value
AND has_double_discount != 1",

array(
'some_value' => $some_value,
'some_other_value' => $some_other_value,
'yet_another_value' => $yet_another_value,
)
);

for_table 参数很可能是 NULL

我试过:

  1. 简单地执行查询而不绑定(bind)参数,就像在带有静态参数的整个完整查询中那样 - 没有用
  2. 不使用 ORM - 工作正常。
  3. 使用问号代替 : 符号 - 不起作用。

话虽这么说,但我可能在这里遗漏了一些明显的东西。非常感谢任何朝着正确方向的插入。

我研究过像 raw_execute 这样的选项,但也不太幸运。

这并不特别重要,但所有值都是数字。

最佳答案

如果您更喜欢单个查询,raw_execute 是您的不二之选。您可以执行以下操作。

ORM::raw_execute("UPDATE products " .
"SET discount_green = :some_value " .
"WHERE category_id = :some_other_value " .
"AND discount_green != :yet_another_value " .
"AND has_double_discount != 1",
array (
"some_value" => $some_value,
"some_other_value" => $some_other_value,
"yet_another_value" => $yet_another_value
)
);

关于php - 原始查询 - 更新多列 - 不适用于 Idiorm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30666373/

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