i'm having problems when using the function ActiveRecord::updateAll()
. Here is the code i use :
Branch::updateAll(
[
'parent' => ':p',
'order' => ':o'
], [
'id' => ':i'
], [
':p' => $line['parent'],
':o' => $line['order'],
':i' => $line['id'],
]);
I get the following error :
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''
I can't find what i'm doing wrong... I tried changing names for the binded parameters and i also tried with 'anonymous' parameters (using ?
instead of :p
) without success
Thanks for your help
Here is the correct version:
Branch::updateAll(
[
'parent' => $line['parent'],
'order' => $line['order'],
],
['id' => $line['id']],
);
Alternative:
Branch::updateAll(
[
'parent' => $line['parent'],
'order' => $line['order'],
],
'id = :id',
[':id' => $line['id']],
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.