【问题标题】:Yii2 select2 database exception number of bound variables does not match number of tokensYii2 select2 数据库异常绑定变量数与令牌数不匹配
【发布时间】:2021-03-09 08:12:21
【问题描述】:

当我在我的 yii 2 应用程序中使用 select2 小部件时,会导致以下错误:

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

执行的 sql 并没有在 Page 模型的 find 函数中应用我的覆盖,如下所示:

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

调试堆栈提示我在第 333 行 ActiveRecord 中的 beforeInsert() 函数和此代码:

$this->node->refresh();

一切看起来都很好,那么有什么问题呢?

【问题讨论】:

    标签: php activerecord yii2 jquery-select2


    【解决方案1】:

    我也遇到了同样的问题,好像是框架的bug! 只需找到 refresh() 函数并在 vendor/yiisoft/yii2/db/ActiveRecord.php 文件中更改以下行

    $query->where($pk);
    

    $query->andWhere($pk);
    

    希望对您有所帮助,我渴望更好的解决方案。

    【讨论】:

      猜你喜欢
      • 2015-07-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多