Jump to content

Recommended Posts

Hey,

 

I want to issue multiple queries in my script using PDO. All of of these queries will either retrieve one row with multiple columns or one row with one column, so I am using either fetch or fetchColumn to get the data.

 

Now, I ran into an error message telling me: "General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll()."

 

If there is only one row being retrieved (and I know this for sure), how is it that unbuffered queries are still active?

 

And whats the most effective way to get around this? I can use fetchAll or loop with fetchColumn or call PDOStatement->closeCursor(); after each query data retrieval statement.

 

Anyone else encounter this? Any advice?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/75722-solved-issuing-multiple-queries-with-pdo/
Share on other sites

Ya know, not showing everyone what you did to fix this doesn't help people in the future who may have the same question. In my case, when using PDO with multiple queries, I always had to make sure that at the end of each query the object was deleted. For instance:

 

$pdo1 = $pdo->query("SELECT * FROM tipsntricks WHERE tipNum = '$tipPage'");
$picRow = $pdo1->fetch(PDO::FETCH_ASSOC);
extract($picRow);
echo "	<title>Tips & Tricks - Tip # {$_GET['tip']} - $tipTitle</title>
<meta name='description' content='$tipBlurb' />";
$pdo1 = null; //HERE
$pdo5 = $pdo->prepare("SELECT * FROM tipsntricks WHERE tipType = '$tipCat' ORDER BY tipNum DESC");
$pdo5->execute();
$num_rows = count($pdo5->fetchAll());
if ($num_rows != 0){
	echo "	<li class='prodcat'><h3>" . ucfirst($tipCat) . "</h3>
		<ul>";
	foreach ($pdo->query("SELECT * FROM tipsntricks WHERE tipType = '$tipCat' ORDER BY tipNum DESC") as $row) {
		echo "<li><a href='http://www.whatever.tv/tips/". $row['tipNum'] . ".php5'>" . $row['tipTitle'] . " </a></li>";
	}
echo "	</ul>
	</li>";
}
$pdo5 = null; //HERE

Youre right skunkbad, my bad, I was too excited to continue coding.. :P

 

My solution was the same as the one you suggested. Just making sure that after every query issued, I delete that query object, thus freeing up the resources needed to make the next query.

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.