<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Handling Binary Data with PDO</title>
	<atom:link href="http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/feed/" rel="self" type="application/rss+xml" />
	<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/</link>
	<description>Random musings on web development and PHP</description>
	<lastBuildDate>Tue, 15 May 2012 09:13:37 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Easy File Encryption &#124; Jeremy Cook</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-1168</link>
		<dc:creator>Easy File Encryption &#124; Jeremy Cook</dc:creator>
		<pubDate>Sun, 20 Mar 2011 16:59:35 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-1168</guid>
		<description>[...] decryption stream filter to the stream returned from PDO on a select operation. Bearing in mind the issues that PDO/MySQL has with returning streams from LOB fields I&#8217;m hoping this should be fairly easy. Hopefully this post will help someone looking to do [...]</description>
		<content:encoded><![CDATA[<p>[...] decryption stream filter to the stream returned from PDO on a select operation. Bearing in mind the issues that PDO/MySQL has with returning streams from LOB fields I&#8217;m hoping this should be fairly easy. Hopefully this post will help someone looking to do [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marko Kozjak</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-800</link>
		<dc:creator>Marko Kozjak</dc:creator>
		<pubDate>Fri, 14 Jan 2011 14:45:48 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-800</guid>
		<description>Update,

since i cannot get this to work any other way i did this...

&lt;code&gt;
function hextostr($x) {
  		$s=&#039;&#039;;
  		foreach(explode(&quot;\n&quot;,trim(chunk_split($x,2))) as $h) $s.=chr(hexdec($h));
  		return($s);
		}
&lt;/code&gt;

this way my data gets changed but it consumes alot of memory so large files are sitll a big problem.

Any recomendation or a hint how to implement:

&lt;code&gt;
$lob = fopen(&#039;data://text/plain;base64,&#039; . base64_encode($lob), &#039;r&#039;);
&lt;/code&gt;

I just cant get it to work.

With regards,
Marko</description>
		<content:encoded><![CDATA[<p>Update,</p>
<p>since i cannot get this to work any other way i did this&#8230;</p>
<p><code><br />
function hextostr($x) {<br />
  		$s='';<br />
  		foreach(explode("\n",trim(chunk_split($x,2))) as $h) $s.=chr(hexdec($h));<br />
  		return($s);<br />
		}<br />
</code></p>
<p>this way my data gets changed but it consumes alot of memory so large files are sitll a big problem.</p>
<p>Any recomendation or a hint how to implement:</p>
<p><code><br />
$lob = fopen('data://text/plain;base64,' . base64_encode($lob), 'r');<br />
</code></p>
<p>I just cant get it to work.</p>
<p>With regards,<br />
Marko</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marko Kozjak</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-790</link>
		<dc:creator>Marko Kozjak</dc:creator>
		<pubDate>Wed, 12 Jan 2011 16:16:06 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-790</guid>
		<description>Hello,

i am having a big problem with this PDO LOB bug. I have alof of files stored in DB2 and currently the only solution i can use is to do this...

&lt;code&gt;
$stmt = $db-&gt;prepare($QSql);
		$stmt-&gt;bindColumn(1, $Podat, PDO::PARAM_LOB);
		$stmt-&gt;bindColumn(2, $FileName, PDO::PARAM_STR);
		$stmt-&gt;execute();
		$stmt-&gt;fetch(PDO::FETCH_BOUND);

             for ($i = 0; $i &lt; $noc; $i = $i+2)
		{
			$PodatPret .=chr(hexdec(substr($Podat, $i, 2)));
		}

                fwrite($Datot, $PodatPret);
		fclose($Datot);
&lt;/code&gt;

This solution is good for small images... but it is very bad for larger files since it takes alot of time to convert to scroll over the file doing substr, hexdec  and chr.

Anyone can help?

Contact me by mail ( kozy_ligh at yahoo dot com ) or answer here please.

Thank you!

With regards,

Marko</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>i am having a big problem with this PDO LOB bug. I have alof of files stored in DB2 and currently the only solution i can use is to do this&#8230;</p>
<p><code><br />
$stmt = $db-&gt;prepare($QSql);<br />
		$stmt-&gt;bindColumn(1, $Podat, PDO::PARAM_LOB);<br />
		$stmt-&gt;bindColumn(2, $FileName, PDO::PARAM_STR);<br />
		$stmt-&gt;execute();<br />
		$stmt-&gt;fetch(PDO::FETCH_BOUND);</p>
<p>             for ($i = 0; $i &lt; $noc; $i = $i+2)<br />
		{<br />
			$PodatPret .=chr(hexdec(substr($Podat, $i, 2)));<br />
		}</p>
<p>                fwrite($Datot, $PodatPret);<br />
		fclose($Datot);<br />
</code></p>
<p>This solution is good for small images&#8230; but it is very bad for larger files since it takes alot of time to convert to scroll over the file doing substr, hexdec  and chr.</p>
<p>Anyone can help?</p>
<p>Contact me by mail ( kozy_ligh at yahoo dot com ) or answer here please.</p>
<p>Thank you!</p>
<p>With regards,</p>
<p>Marko</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Cook</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-11</link>
		<dc:creator>Jeremy Cook</dc:creator>
		<pubDate>Thu, 04 Mar 2010 20:58:19 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-11</guid>
		<description>In reply to Dennis: I think you have a very valid point but Josh&#039;s solution is the only one I&#039;ve seen so far that completely gets around this bug. For my purposes simply writing the binary data to the output was enough as all I needed to do was to display the image. For anything else I&#039;d probably need a stream, which is where Josh&#039;s solution comes in. I completely agree with you in that it&#039;s not optimal from a memory consumption point of view. The only true solution would be for this bug to be fixed I guess.</description>
		<content:encoded><![CDATA[<p>In reply to Dennis: I think you have a very valid point but Josh&#8217;s solution is the only one I&#8217;ve seen so far that completely gets around this bug. For my purposes simply writing the binary data to the output was enough as all I needed to do was to display the image. For anything else I&#8217;d probably need a stream, which is where Josh&#8217;s solution comes in. I completely agree with you in that it&#8217;s not optimal from a memory consumption point of view. The only true solution would be for this bug to be fixed I guess.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-10</link>
		<dc:creator>Dennis</dc:creator>
		<pubDate>Thu, 04 Mar 2010 20:33:42 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-10</guid>
		<description>In reply to Josh: The whole idea of handling LOBs as streams is to greatly reduce memory load. While your workaround will work, it will keep the whole LOB in memory, and that LOB could be a few megs picture on a pretty busy site...</description>
		<content:encoded><![CDATA[<p>In reply to Josh: The whole idea of handling LOBs as streams is to greatly reduce memory load. While your workaround will work, it will keep the whole LOB in memory, and that LOB could be a few megs picture on a pretty busy site&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dennis</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-9</link>
		<dc:creator>Dennis</dc:creator>
		<pubDate>Thu, 04 Mar 2010 20:29:20 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-9</guid>
		<description>Yeah, this is a bit of shame that this bug is still around after three years. I reported it while writing my Learning PHP Data Objects book back in March 2007, and I am still very surprised it&#039;s not fixed.

http://www.packtpub.com/Learning-PHP-Data-Objects-Open-Source/book</description>
		<content:encoded><![CDATA[<p>Yeah, this is a bit of shame that this bug is still around after three years. I reported it while writing my Learning PHP Data Objects book back in March 2007, and I am still very surprised it&#8217;s not fixed.</p>
<p><a href="http://www.packtpub.com/Learning-PHP-Data-Objects-Open-Source/book" rel="nofollow">http://www.packtpub.com/Learning-PHP-Data-Objects-Open-Source/book</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: abcphp.com</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-8</link>
		<dc:creator>abcphp.com</dc:creator>
		<pubDate>Thu, 04 Mar 2010 10:45:00 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-8</guid>
		<description>&lt;strong&gt;Handling Binary Data with PDO...&lt;/strong&gt;

I’m a great fan of the PDO database access library in PHP 5 and use it for all of my database work in PHP. I love its’ clean, object oriented syntax and great support for prepared statements. I also like the fact that it supports most of the most commo...</description>
		<content:encoded><![CDATA[<p><strong>Handling Binary Data with PDO&#8230;</strong></p>
<p>I’m a great fan of the PDO database access library in PHP 5 and use it for all of my database work in PHP. I love its’ clean, object oriented syntax and great support for prepared statements. I also like the fact that it supports most of the most commo&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh Johnston</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-7</link>
		<dc:creator>Josh Johnston</dc:creator>
		<pubDate>Wed, 03 Mar 2010 22:30:22 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-7</guid>
		<description>You can also try this code to convert your string data into a stream first then continue accessing it as if it were a string. I haven&#039;t tested if the base64 data will output correctly or not but that is the basics of turning any in-memory data source into a stream

[php]
if (is_string($lob)) {
   // $lob is now a resource pointing to a stream composed of the data at hand
   $lob = fopen(&#039;data://text/plain;base64,&#039; . base64_encode($lob), &#039;r&#039;);
}

fpassthru($lob);
[/php]</description>
		<content:encoded><![CDATA[<p>You can also try this code to convert your string data into a stream first then continue accessing it as if it were a string. I haven&#8217;t tested if the base64 data will output correctly or not but that is the basics of turning any in-memory data source into a stream</p>
<pre class="brush: php; title: ; notranslate">
if (is_string($lob)) {
   // $lob is now a resource pointing to a stream composed of the data at hand
   $lob = fopen('data://text/plain;base64,' . base64_encode($lob), 'r');
}

fpassthru($lob);
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Cook&#8217;s Blog: Handling Binary Data with PDO &#124; Webs Developer</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-5</link>
		<dc:creator>Jeremy Cook&#8217;s Blog: Handling Binary Data with PDO &#124; Webs Developer</dc:creator>
		<pubDate>Wed, 03 Mar 2010 22:08:07 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-5</guid>
		<description>[...] Cook has put together a quick guide for something that can be tricky when using PDO in PHP - handling binary data in the return from your queries.   I like the fact that if I needed to use MS SQL Server, Oracle or [...]</description>
		<content:encoded><![CDATA[<p>[...] Cook has put together a quick guide for something that can be tricky when using PDO in PHP &#8211; handling binary data in the return from your queries.   I like the fact that if I needed to use MS SQL Server, Oracle or [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy Cook&#8217;s Blog: Handling Binary Data with PDO &#124; Development Blog With Code Updates : Developercast.com</title>
		<link>http://jeremycook.ca/2010/02/21/handling-binary-data-with-pdo/comment-page-1/#comment-4</link>
		<dc:creator>Jeremy Cook&#8217;s Blog: Handling Binary Data with PDO &#124; Development Blog With Code Updates : Developercast.com</dc:creator>
		<pubDate>Wed, 03 Mar 2010 21:36:22 +0000</pubDate>
		<guid isPermaLink="false">http://jeremycook.ca/?p=64#comment-4</guid>
		<description>[...] Cook has put together a quick guide for something that can be tricky when using PDO in PHP - handling binary data in the return from your queries.   I like the fact that if I needed to use MS SQL Server, Oracle or [...]</description>
		<content:encoded><![CDATA[<p>[...] Cook has put together a quick guide for something that can be tricky when using PDO in PHP &#8211; handling binary data in the return from your queries.   I like the fact that if I needed to use MS SQL Server, Oracle or [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

