NOTICE

[PDO]

Date : 2019. 11. 7. 13:44 Category : Programming/PHP

Fatal error: Uncaught exception 'PDOException' with message '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.' in /home/xxxxx/www/xxxx/xxxxx.php:149 Stack trace: #0 /home/xxxxx/www/xxxx/xxxxx.php(149): PDO->prepare('SELECT `num` ...') #1 {main} thrown in /home/xxxxx/www/xxxx/xxxxx.php on line 149

PDO를 사용하다 보면 위와 같은 오류가 나오는 경우가 있습니다. 대충 내용은 버퍼되지 않은 쿼리가 활성화되어 있는 중에 쿼리를 실행할 수 없다. fetchAll()을 사용하는 걸 고려해 봐라. 대안으로 MYSQL_ATTR_USE_BUFFERED_QUERY 속성을 설정하여 쿼리 버퍼링을 활성화할 수 있다. 이런 의미입니다.

fetchAll()을 써도 오류는 마찬가지로 계속 나고 다른 대안으로 나온 MYSQL_ATTR_USE_BEFFERED_QUERY 속성을 활성화하면 됩니다.

$sth->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);