Jump to content

PDO and MySql, error 2014


next

Recommended Posts

I'm following a book on creating a Shopping Cart and stumbled upon a problem. I researched it online and it seems that this is a bug with php 5.2, i was unsuccessful at finding a remedy though.

Does anyone know how to fix this?

 

My error:

ERRNO: 256

 

TEXT: 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.

 

LOCATION: E:\PortableApps\WOS\www\tshirtshop\business\database_handler.php, line: 75, at June 30, 2008, 6:36 pm

 

Showing backtrace:

trigger_error("SQLSTATE[HY000]: General error: 2014 Cannot execute queries whil...", "256")# line  75, file: E:\PortableApps\WOS\www\tshirtshop\business\database_handler.php

DatabaseHandler.GetAll("CALL catalog_get_departments_list()")# line    7, file: E:\PortableApps\WOS\www\tshirtshop\business\catalog.php

Catalog.GetDepartments()# line  14, file: E:\PortableApps\WOS\www\tshirtshop\presentation\departments_list.php

DepartmentsList.init()# line  10, file: E:\PortableApps\WOS\www\tshirtshop\presentation\smarty_plugins\function.load_presentation_object.php

smarty_function_load_presentation_object(Array[2], Object: Application)# line    5, file: E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%A5^A5A^A5A1C73D%%departments_list.tpl.php

include("E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%A5...")# line 1871, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php

Smarty._smarty_include(Array[2])# line  40, file: E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%41^412^412F4E3D%%store_front.tpl.php

include("E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%41...")# line 1258, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php

Smarty.fetch("store_front.tpl", null, null, true)# line 1108, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php

Smarty.display("store_front.tpl")# line  13, file: E:\PortableApps\WOS\www\tshirtshop\index.php

 

Code:

<?php
//generic data access functionality
class DatabaseHandler {
//hold an instance of the PDO class
private static $_mHandler;

//private constructor to prevent direct creation of object
private function __construct() {
}

//return an initialized database handler
private static function GetHandler() {
	//create DB connection if not yet connected.
	if(!isset(self::$_mHandler)) {
		//execute code catching potential exceptions
		try {
			//create a new PDO class instance
			self::$_mHandler = new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD, array(PDO::ATTR_PERSISTENT => DB_PERSISTENCY));
			self::$_mHandler->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
			//configure PDO to throw exceptions
			self::$_mHandler -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
		}
		catch (PDOException $e) {
			//close the database handler and trigger an error
			self::Close();
			trigger_error($e -> getMessage(), E_USER_ERROR);
		}
	}
	//return database handler
	return self::$_mHandler;
}

//Clear the PDO class instance
public static function Close() {
	self::$_mHandler = null;
}
//wrapper method for PDOStatement::execute()
public static function Execute($sqlQuery, $params = null) {
	//try to execute an SQL query or a stored procedure
	try {
		//get DB handler
		$database_handler = self::GetHandler();

		//Prepare the query for execution
		$statement_handler = $database_handler -> prepare($sqlQuery);
		//execute query
		$statement_handler -> execute($params);
	}
	catch (PDOException $e){
		//close the DB handler and trigger an error
		self::Close();
		trigger_error($e -> getMessage(), E_USER_ERROR);
	}
}
//wrapper method for PDOStatement::fetchAll()
public static function GetAll($sqlQuery, $params = null, $fetchStyle = PDO::FETCH_ASSOC) {
	//initialize the return value to null
	$result = null;

	//try to execute an SQL query or a stored procedure
	try {
		//get DB handler
		$database_handler = self::GetHandler();

		//prepare the the query
		$statement_handler = $database_handler -> prepare($sqlQuery);
		//execute query
		$statement_handler -> execute($params);
		//fetch result
		$result = $statement_handler -> fetchAll($fetchStyle);
	}
	//trigger an error if an exception was thrown when executing the SQL query
	catch (PDOException $e){
		self::Close();
		trigger_error($e -> getMessage(), E_USER_ERROR);
	}
	return $result;
}
public static function GetRow($sqlQuery, $params = null, $fetchStyle = PDO::FETCH_ASSOC) {
	//initialize the return value to null
	$result = null;
	try {
		$database_handler = self::GetHandler();
		$statement_handler = $database_handler -> prepare($sqlQuery);
		$statement_handler -> execute($params);
		$result = $statement_handler -> fetch($fetchStyle);
	}
	catch(PDOException $e) {
		self::Close();
		trigger_error($e -> getMessage(), E_USER_ERROR);
	}

	return $result;
}

//return the first column value from a row
public static function GetOne($sqlQuery, $params = null) {
	$result = null;
	try {
		$database_handler = self::GetHandler();
		$statement_handler = $database_handler -> prepare($sqlQuery);
		$statement_handler -> execute($params);
		$result = $statement_handler -> fetch(PDO::FETCH_NUM);
		//save the first value of the result set to $result
		$result = $result[0];
	}
	catch(PDOException $e) {
		self::Close();
		trigger_error($e -> getMessage(), E_USER_ERROR);
	}

	return $result;
}
}
?>

Link to comment
Share on other sites

Did you try the custom dll mentioned here ?

 

There's also several workarounds listed in that bug report.  I would start trying them one by one (especially the ones reported by others to work).  You could be waiting a long time to get a response here..

 

I'll also recommend that this thread be moved to the mysql section, as you will likely get noticed by the mysql experts over there.

Link to comment
Share on other sites

Nah, it gives me another error:

ERRNO: 256
					  
TEXT: could not find driver
					  
LOCATION: E:\PortableApps\WOS\www\tshirtshop\business\database_handler.php, line: 26, at July 1, 2008, 10:51 am
					  
Showing backtrace: 
trigger_error("could not find driver", "256")# line   26, file: E:\PortableApps\WOS\www\tshirtshop\business\database_handler.php
DatabaseHandler.GetHandler()# line   63, file: E:\PortableApps\WOS\www\tshirtshop\business\database_handler.php
DatabaseHandler.GetAll("CALL catalog_get_departments_list()")# line    7, file: E:\PortableApps\WOS\www\tshirtshop\business\catalog.php
Catalog.GetDepartments()# line   14, file: E:\PortableApps\WOS\www\tshirtshop\presentation\departments_list.php
DepartmentsList.init()# line   10, file: E:\PortableApps\WOS\www\tshirtshop\presentation\smarty_plugins\function.load_presentation_object.php
smarty_function_load_presentation_object(Array[2], Object: Application)# line    5, file: E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%A5^A5A^A5A1C73D%%departments_list.tpl.php
include("E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%A5...")# line 1871, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php
Smarty._smarty_include(Array[2])# line   40, file: E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%41^412^412F4E3D%%store_front.tpl.php
include("E:\PortableApps\WOS\www\tshirtshop\presentation\templates_c\%%41...")# line 1258, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php
Smarty.fetch("store_front.tpl", null, null, true)# line 1108, file: E:\PortableApps\WOS\www\tshirtshop\libs\smarty\Smarty.class.php
Smarty.display("store_front.tpl")# line   13, file: E:\PortableApps\WOS\www\tshirtshop\index.php

It looks like this dll is not recognized.

Link to comment
Share on other sites

Hmm.. well if it's practical, you might try a more recent php build.  The latest stable release is 5.2.6, and there's quite a few PDO fixes between 5.2 and 5.2.6, including bug 39759.

 

But it looks like bug 39858 may still cause trouble even with 5.2.6.  At least there are some workarounds in that bug report though.

 

In bug 42499 someone says that this should be fixed in the next release of PDO_MYSQLND, whatever that means.

Link to comment
Share on other sites

I use server on a stick, they are only up to 5.2.5, i tried Server2Go which has 5.2.6 on it, but i couldn't get that damn server to work.

I really hope that they will fix this problem, because this is an excellent book(By Christian Darie btw, it's his blog that you linked to in your first post.). Well i tried to work around it, but i'm a NOonb to php and was unsuccessful. I guess i'll read something else for now.

 

Thanks.

Link to comment
Share on other sites

  • 1 year later...
  • 9 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.