PDO “Uncaught exception 'PDOException' .. Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll().”

前端 未结 3 384
萌比男神i
萌比男神i 2021-01-17 17:56

I know this question has been asked many times, but I\'ve read the answers to many of the questions and still cannot understand why I am receiving this error:

3条回答
  •  [愿得一人]
    2021-01-17 18:46

    you need to fetch until a row fetch attempt fails. I know you may only have one row in the result set and think one fetch is enough, but its not.

    you probably have other statements where you didn't fully "fetch until a fetch failed". Yes, i see that you fetch until the fetch failed for one of the statements.

    also, see closecursor()

    $sql = "select * from test.a limit 1";
    $stmt = $dbh->prepare($sql);
    $stmt->execute(array());
    $row = $stmt->fetch();
    $stmt->closeCursor();
    

    or

    $sql = "select * from test.a limit 1";
    $stmt = $dbh->prepare($sql);
    $stmt->execute(array());
    list($row) = $stmt->fetchAll(); //tricky
    

提交回复
热议问题