What is causing PDO error Cannot execute queries while other unbuffered queries are active?

前端 未结 4 663
野的像风
野的像风 2021-02-01 09:01

I have the following code:

$dbh = new PDO(\"mysql:host=$host;dbname=$dbname\", $user, $pass);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbh->         


        
4条回答
  •  花落未央
    2021-02-01 09:20

    This is not necessarily the answer to this question, but this may help somebody in the future.

    I came across exactly the same error and it took hours to discover what was wrong. It turned out it was just a extremely minor syntax issue all along. If you're not actually using any buffering, but still have this error, like I did, this could be your issue - so check your code.

    I was doing my normal database queries when I came across this error -- not purposely using any buffering techniques -- so I highly doubted it had anything to do with buffering. I read every SO question about it and looked deeper in to it.

    This was my STUPID syntax issue:

    $SQL = "UPDATE articles SET
                topicID = :topic;    <-------- semicolon - woops!
                heading = :heading,
                subheading = :subheading,
                keywords = :keywords,
                rawContent = :rawContent,
                content = :content,
                ...
                ...
    

    This resulted in me getting this buffering error. I fixed the code and it went away. What was most annoying, was the fact the PDO error was pointing at another query, the next query, but that query was in a function elsewhere in the code, and that through me well off course for a while!

提交回复
热议问题