我使用的是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
。
I have try:
- 简单地执行查询,而不绑定参数,就像在一个完整的查询中使用静态参数一样-不起作用
- 使用问号代替
:
符号-不工作。
话虽如此,我可能在这里遗漏了一些明显的东西。
我已经研究了像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
)
);