gpt4 book ai didi

php - yii 2 参数未在 updateAll 函数中正确绑定(bind)

转载 作者:行者123 更新时间:2023-11-28 23:47:17 26 4
gpt4 key购买 nike

我在使用函数 ActiveRecord::updateAll() 时遇到问题。这是我使用的代码:

Branch::updateAll(
[
'parent' => ':p',
'order' => ':o'
], [
'id' => ':i'
], [
':p' => $line['parent'],
':o' => $line['order'],
':i' => $line['id'],
]);

我收到以下错误:

Exception (Database Exception) 'yii\db\Exception' with message 
'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
The SQL being executed was: UPDATE `branch` SET `parent`=':p', `order`=0 WHERE `id`=':i''

我找不到我做错了什么......我尝试更改绑定(bind)参数的名称,我也尝试使用“匿名”参数(使用 ? 而不是 :p)但没有成功

谢谢你的帮助

最佳答案

这是正确的版本:

Branch::updateAll(
[
'parent' => $line['parent'],
'order' => $line['order'],
],
['id' => $line['id']],
);

备选方案:

Branch::updateAll(
[
'parent' => $line['parent'],
'order' => $line['order'],
],
'id = :id',
[':id' => $line['id']],
);

关于php - yii 2 参数未在 updateAll 函数中正确绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33389948/

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