Reputation: 2622
I started to see this error the other day in my Laravel application. The weird thing is I haven't pushed any code changes up and it started to give this error.
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.
This is one of the queries it is complaining about:
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]);
}
I am using: MariaDB 10.2.36
Would anyone have any recommendations on how to fix this?
Upvotes: 0
Views: 1517
Reputation: 42736
DB::select()
will expect to get a result set, and likely hangs things up waiting for one. Instead, according to documentation, you should be using DB::insert()
to perform an INSERT
SQL statement.
Upvotes: 2