SQLSTATE[HY000]_ General error_ 2014 Cannot execute queries while other unbuffered queries are active
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.
当你遇到 SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active
这类错误时,通常是因为你在执行查询时使用了非缓冲查询(unbuffered query),而在查询结果尚未处理完毕之前又尝试执行新的查询。
解决方法
- 使用
PDOStatement::fetchAll()
- 启用查询缓冲
详细步骤
1. 使用 PDOStatement::fetchAll()
如果你的查询结果不需要逐行处理,可以直接使用 PDOStatement::fetchAll()
方法一次性获取所有结果。