Laravel 未缓冲的查询处于活动状态错误

Laravel unbuffered queries are active error

前几天我开始在我的 Laravel 应用程序中看到这个错误。奇怪的是我没有推送任何代码更改,它开始给出这个错误。

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.

这是它抱怨的查询之一:

public function addAgents($year)
{
    $result = DB::select("
        INSERT INTO {agents}
        (
            first_name,
            last_name,
            name
        )
        SELECT
        t.first_name,
        t.last_name,
        t.name
        FROM
        (
            SELECT DISTINCT
            first_name,
            last_name,
            CONCAT(first_name, ' ', last_name) AS name
            FROM {data_mart} d
            AND program_year = :year
        ) AS t
        ON DUPLICATE KEY UPDATE
        first_name = t.first_name,
        last_name = t.last_name,
        name = t.name,
    ", [':year' => $year]);
}

我正在使用:MariaDB 10.2.36

有人可以就如何解决这个问题提出任何建议吗?

DB::select() 将期望得到一个结果集,并且可能会挂断等待结果集。相反,according to documentation,您应该使用 DB::insert() 来执行 INSERT SQL 语句。