Skip to content
Advertisement

Yii2 select2 database exception number of bound variables does not match number of tokens

when i use select2 widget in my yii 2 applicaton, it will cause the following error:

SQLSTATE [HY093]: Invalid parameter number: number of bound variables does not match number of tokens
The SQL being executed was: SELECT * FROM `page` WHERE `page`.`id`=6

The executed sql does not apply my override in find function of Page model as follow:

public static function find()
{
    return parent::find()->where(['websiteId' => Yii::$app->website->id]);
}

Debug stack hint me to beforeInsert() function in ActiveRecord at line 333 & this code:

$this->node->refresh();

Every thing seems ok, so whats wrong?

Advertisement

Answer

I had a same problem, It seems to be a bug in framework! Just find refresh() function & change the following line in vendor/yiisoft/yii2/db/ActiveRecord.php file

$query->where($pk);

to

$query->andWhere($pk);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement