作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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
。
我试过:
:
符号 - 不起作用。话虽这么说,但我可能在这里遗漏了一些明显的东西。非常感谢任何朝着正确方向的插入。
我研究过像 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/
我是一名优秀的程序员,十分优秀!