SQLSTATE[HY000]: General error: 2014 错误如何处理

本地服务器,运行laravel项目,正常运行、生产服务器提示错误.
这里的sql代码是debug里面输出的

update `cy_product_type` set `parentid` = '3', `tree` = '0-1-3-551' where `id` = '551'
update cy_product_type set tree = CONCAT('0-1-3-551-',id) where tree like '0-1-550-551-%'

请问这个是什么错误?

SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  Consider using PDOStatement::fetchAll().  Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. (SQL: update cy_product_type set tree = CONCAT('0-1-3-551-',id) where tree like '0-1-550-551-%')
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

@LiamHao 没有并发,我只是在mode中updated事件执行更新代码。目前不知道如何调试,请指点下。
而且本地开发环境正常,生产环境报错。。

file

最后自己重写了一下代码,解决了。原因不清楚..

解决办法:把模型事件updated中的代码改为:

        static::updated(function ($model) {
            $dirty    = $model->getDirty();
            $original = $model->getRawOriginal();

            // 移动节点
            if (isset($dirty['parentid'])) {
                DB::table('product_type')->where('tree', 'like', $original['tree'] . '-%')->update(['tree' => DB::raw("CONCAT('{$model->tree}-',id)")]);
                $child = DB::table('product_type')->where('parentid', $original['parentid'])->count();
                if (!$child) {
                    DB::table('product_type')->where('id', $original['parentid'])->update(['child' => 0]);
                }
            }
        });
3年前 评论
LiamHao 3年前
讨论数量: 2

并发的情况下,一个查询还没有结束,另一个查询开始。尝试将MYSQL_ATTR_USE_BUFFERED_QUERY设为 true
config/database.php中:

    'connections' => [
        'mysql' => [
            ...
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
                // 加在这里
                PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true,
            ]) : [],
        ],
    ],
3年前 评论
91it (楼主) 3年前

@LiamHao 没有并发,我只是在mode中updated事件执行更新代码。目前不知道如何调试,请指点下。
而且本地开发环境正常,生产环境报错。。

file

最后自己重写了一下代码,解决了。原因不清楚..

解决办法:把模型事件updated中的代码改为:

        static::updated(function ($model) {
            $dirty    = $model->getDirty();
            $original = $model->getRawOriginal();

            // 移动节点
            if (isset($dirty['parentid'])) {
                DB::table('product_type')->where('tree', 'like', $original['tree'] . '-%')->update(['tree' => DB::raw("CONCAT('{$model->tree}-',id)")]);
                $child = DB::table('product_type')->where('parentid', $original['parentid'])->count();
                if (!$child) {
                    DB::table('product_type')->where('id', $original['parentid'])->update(['child' => 0]);
                }
            }
        });
3年前 评论
LiamHao 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!