Category Archives: PHP

Uncaught exception ‘PDOException’:General error: 2014

I received this error while I was testing out a prepared statement using PDO. This happened when criteria from a textbox added to the query’s WHERE clause within the prepared statement.

Fatal error: Uncaught exception ‘PDOException’ with message ‘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.’ path-to-file/filename.php: +280 Stack trace: #0 path-to-file/filename.php (280):PDO->prepare(‘SELECT * FROM B…’) #1 {main} thrown in /path-to-file/filename.php on line {LINE#}

Turns out the connection string needed an attribute set so adding the line below solved the issue:
$conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);

Now the connection string looks as follows:

$dbhost = ‘ipaddress’
$dbname = ‘database_name’
$dbuser = ‘user_name’
$dbpass = ‘password’
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
//added this line to set the MYSQL_ATTR_USE_BUFFERED_QUERY attribute
 $conn->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);

and then all was good

Enable error messages with PHP

Use the code below to display error messages while debugging a PHP web page. You should only use this on local development server as anyone viewing the page will see some server-side logic.

It has gotten me out of many a jam….

 ini_set("display_errors", 1);  //Display errors to the screen
 ini_set("track_errors", 1);  //Set last error message to variable ($php_errormsg)
 ini_set("html_errors", 1);  //Turn off HTML tags in error messages.
 error_reporting(E_ALL);  //Catch all errors and warnings

More info here :