duanchigeng4313 2015-11-27 04:03
浏览 95
已采纳

CakePHP 3.0:SQLSTATE [HY000]:一般错误:1个SQL变量太多

I occasionally keep getting an issue with CakePHP 3.1.3 that show this error SQLSTATE[HY000]: General error: 1 too many SQL variables. It is quite hard to re-produce this at my end as it comes and goes. I've attached an image of this error.

CakePHP 3.0 - SQLSTATE[HY000]: General error: 1 too many SQL variables

I've observed that usually I get the error with the code I've provided below. The code below will get multiple id based on multiple checkboxes selection. After which, it deletes the student based on the selected id. The question I am asking is whether the error I am getting is caused by my code or is it due to the Debugkit that I've seen someone posted a similar question in this link(https://github.com/cakephp/cakephp/issues/7373). If it caused by the Debugkit, how can I swiftly resolve it?

$deleteList = $this->request->data['selected'];

$classids = $studentclassTable->find()
->select(['classroom_id'=>'Studentclassrooms.classroom_id'])
->where(['student_id IN' => $deleteList])
->hydrate(false)
->toArray();     


foreach($deleteList as $id) {
    $student =  $this->Students->findById($id)->first();                        
    if($student){
        array_push($usernames, $student['firstname'].' '.$student['lastname']);
        $this->Students->delete($student);
    }
}
  • 写回答

1条回答 默认 最新

  • doutang3760 2015-11-27 16:47
    关注

    If you look closely at the stacktrace, you should see that this stems from Debug Kit, it's the garbage collection mechanism that cleans the request history.

    Looking at the query, it seems that your Debug Kit version is not up to date, the latest version will use a NOT IN condition (since 3.1.7), where by default only a maximum of 20 rows is being kept, and thus the same amout of placeholders will be set in the query.

    See https://github.com/cakephp/debug_kit/pull/381

    The maximum number of rows to keep can be configured via the global DebugKit.requestCount config option.

    Long story short, update your Debug Kit dependency.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。