Search This Blog

Saturday, July 16, 2011

fix bug pdo_mysql

This is bug of pdo_mysql that I lost many time to fix it:
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.
This is a solution when using pdo in zendframeword, it is very simple:

                $objDB = Zend_Registry::get('objDBReadWrite');
                $stmt = $objDB->prepare('call storedprocedure_name(:type, :start,:limit,@total);');
                $stmt -> bindParam("type", $type, PDO::PARAM_INT, 1);
                $stmt -> bindParam("start", $start, PDO::PARAM_INT, 10);
                $stmt -> bindParam("limit", $limit, PDO::PARAM_INT, 10);
                $stmt -> execute();
                $arrResults = $stmt->fetchAll();
                $stmt -> closeCursor();
                $objOut = $objDB -> query("select @total");
                $arrOut = $objOut -> fetch();
                $total = $arrOut['@total'];
                $stmt -> closeCursor();
                $objDB->closeConnection();

No comments:

Post a Comment