Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8578405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:22:52+00:00 2026-06-11T20:22:52+00:00

I have run into an Exception while using PDO with PHP5.4 and MySql. I

  • 0

I have run into an Exception while using PDO with PHP5.4 and MySql.

I have read almost every other post, blog, manual, snippet, everything I can related to this error and have tried everything I have seen with no luck.

So I am hoping it is specific to something I have done wrong in my particular code and you can point it out to me.

Here is the 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.

Here are the parts of code that lead to this error:

First Part:

        $stmt = $this->dbConn->prepare("CALL getPopularProducts()");
        $stmt->execute();
        $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);

        //$stmt->closeCursor();

        foreach ($rows as $row) {
            $p = new entity\LightingPole();
             /* doing basic set stuff here so code omitted */

            // apply category to product
            $categroyTranslator = new ProductCategoryTranslator();
            $categroyTranslator->applyProductCategory($p);

Second part:

        public function applyProductCategory(entity\Product $product) {
            $productId = $product->getProductId();
            try {
               /** exception thrown on this line **/
               $stmt = $this->dbConn->prepare("CALL getCategoryByProductId(?)"); 

               $stmt->bindParam(1, $productId, \PDO::PARAM_INT);
               $stmt->execute();

               while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)){
                   $category = new entity\ProductCategory();

                   $product->setCategory($category);
               }  
             }
             catch (\PDOException $e) {
                 echo $e->getMessage();
                 print($e->getTraceAsString());
             }
         }

Here is my database class:

namespace lib\database;

class Database
{
    protected static $instance;

    public static function getInstance()
    {
        if(self::$instance == null)
        {
            $dsn = "mydsn";
            $user = "myuser";
            $password = "mypassword";
            self::$instance->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
            self::$instance->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
            self::$instance->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        }
        return self::$instance;
    }

    private function __construct() {}

    private function __clone() {}
}

You may notice I have a call to $stmt->closeCursor() which I have commented out. When I include this line of code I get the following error:

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

Now to explain it in plain functionality terms, what I am basically doing here is getting a list of popular products, looping through them and getting all the associated product data such as ProductCategory etc…

So this error, happens for the first product in the loop only, i.e. the second time I call applyProductCategory() it works fine, no problem. The other thing is that below applyProductCategory are about 4 more calls to retrieve other types of associated data and there are never any errors thrown while doing that either.

So in the end, all my popular products are fine, except the very first product never has a ProductCategory associated with it.

Looking forward to finding out what I have missed along the way to cause this. Hopefully you can point me in the right directions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:22:53+00:00Added an answer on June 11, 2026 at 8:22 pm

    Trying using unset($stmt) right before where it’s throwing the error

        unset($stmt);
        $stmt = $this->dbConn->prepare("CALL getCategoryByProductId(?)");  
    

    I ran into the same error before and that fixed it for some reason. I found the answer here previously PDO Unbuffered queries

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have the luck to run into the funniest problems while deploying
I have run into a problem with Eclipse Indigo, attempting to start up my
I have run into a little problem. I am connecting to a webservice that
I have run into a couple of similar quirks regarding uint usage in both
I have run into a situation where I want to ensure that a compound
I have run into a problem trying to modify a form I myself have
I have run into a bit of a problem here: I had a problem-specific
I have run into a problem w/ my model for databinding in WPF. I
I have run into a very strange behaviour I can’t make sense of. I
I have run into a problem... I'm trying to use QTKit in an application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.