<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Stormwild Interactive &#187; PHP5</title>
	<atom:link href="http://blog.stormwild.net/tag/php5/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.stormwild.net</link>
	<description>Web Development</description>
	<lastBuildDate>Wed, 07 Jul 2010 14:59:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Cannot execute queries while other unbuffered queries are active</title>
		<link>http://blog.stormwild.net/programming/cannot-execute-queries-while-other-unbuffered-queries-are-active/</link>
		<comments>http://blog.stormwild.net/programming/cannot-execute-queries-while-other-unbuffered-queries-are-active/#comments</comments>
		<pubDate>Tue, 21 Apr 2009 13:34:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP5]]></category>

		<guid isPermaLink="false">http://stormwild.net/blog/?p=17</guid>
		<description><![CDATA[Cannot execute queries while other unbuffered queries are active Can&#8217;t execute subsequent query after multiple queries from same Pdo_Mysql-&#62;exec() call Can&#8217;t execute multiple stored procedures with Pdo_Mysql Using the following code found in the Zend Framework Quickstart: Create a Model &#8230; <a href="http://blog.stormwild.net/programming/cannot-execute-queries-while-other-unbuffered-queries-are-active/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://bugs.php.net/bug.php?id=44081" target="_blank">Cannot execute queries while other unbuffered queries are active</a></p>
<p><a href="http://framework.zend.com/issues/browse/ZF-5576" target="_blank">Can&#8217;t execute subsequent query after multiple queries from same Pdo_Mysql-&gt;exec() call</a></p>
<p><a href="http://framework.zend.com/issues/browse/ZF-4951" target="_blank">Can&#8217;t execute multiple stored procedures with Pdo_Mysql</a></p>
<p>Using the following code found in the <a href="http://framework.zend.com/docs/quickstart/create-a-model-and-database-table" target="_blank">Zend Framework Quickstart: Create a Model and Database Table</a></p>
<pre><span class="comment">// this block executes the actual statements that were loaded from </span>
<span class="comment">// the schema file.</span>
<span class="keyword">try</span> {
    <span class="variable">$schemaSql</span> = file_get_contents(<span class="string">'./schema.sqlite.sql'</span>);
    <span class="comment">// use the connection directly to load sql in batches</span>
    <span class="variable">$dbAdapter</span>-&gt;getConnection()-&gt;exec(<span class="variable">$schemaSql</span>);
    <span class="keyword">echo</span> PHP_EOL;
    <span class="keyword">echo</span> <span class="string">'Database Created'</span>;
    <span class="keyword">echo</span> PHP_EOL;

    <span class="keyword">if</span> (<span class="variable">$withData</span>) {
        <span class="variable">$dataSql</span> = file_get_contents(<span class="string">'./data.sqlite.sql'</span>);
        <span class="comment">// use the connection directly to load sql in batches</span>
        <span class="variable">$dbAdapter</span>-&gt;getConnection()-&gt;exec(<span class="variable">$dataSql</span>);
        <span class="keyword">echo</span> <span class="string">'Data Loaded.'</span>;
        <span class="keyword">echo</span> PHP_EOL;
    }

} <span class="keyword">catch</span> (<span class="keyword">Exception</span> <span class="variable">$e</span>) {
    <span class="keyword">echo</span> <span class="string">'AN ERROR HAS OCCURED:'</span> . PHP_EOL;
    <span class="keyword">echo</span> <span class="variable">$e</span>-&gt;getMessage() . PHP_EOL;
    <span class="keyword">return</span> false;
}</pre>
<p>Note that $dbAdapter-&gt;getConnection()-&gt;exec() gets called twice.</p>
<p>I encountered this issue when calling Pdo_Mysql-&gt;exec() or in the Zend Framework calling $dbAdapter-&gt;getConnection()-&gt;exec($schemaSql) one after the other.</p>
<p>One way to prevent the error was to call $dbAdapter-&gt;closeConnection() after each exec call. Another way I worked around this problem was to just execute the $schemaSql and the $dataSql in one exec call like below;</p>
<pre>$schemaSql = file_get_contents('schema.sql', 1);
$dataSql = file_get_contents('data.sql', 1);
// use the connection directly to load sql in batches
$dbAdapter-&gt;getConnection()-&gt;exec($schemaSql . $dataSql);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.stormwild.net/programming/cannot-execute-queries-while-other-unbuffered-queries-are-active/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
