<?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>Too Far Afield &#187; binary</title>
	<atom:link href="http://blog.nachtarbeiter.net/tag/binary/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nachtarbeiter.net</link>
	<description></description>
	<lastBuildDate>Mon, 09 Jan 2012 05:41:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Storing binary data inside a MySQL database</title>
		<link>http://blog.nachtarbeiter.net/2009/04/28/storing-binary-data-inside-a-mysql-database/</link>
		<comments>http://blog.nachtarbeiter.net/2009/04/28/storing-binary-data-inside-a-mysql-database/#comments</comments>
		<pubDate>Tue, 28 Apr 2009 05:52:33 +0000</pubDate>
		<dc:creator>Patrick</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[binary]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.nachtarbeiter.net/?p=743</guid>
		<description><![CDATA[Sometimes you need to store binary data inside a MySQL database. While there are various field types for binary data in MySQL, its handling of binary data has a share of different problems. As far as I know you might hit some bugs, if you&#8217;re using non-standard connection encodings or character sets. Also, binary data [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to store binary data inside a <cite>MySQL</cite> database. While there are various field types for binary data in <cite>MySQL</cite>, its handling of binary data has a share of different problems. As far as I know you might hit some bugs, if you&#8217;re using non-standard connection encodings or character sets. Also, binary data is a hell to escape properly. For example, if you store <code>S????'x7?ma?X?UHMh?</code> inside the <cite>MySQL</cite> database you might end up with <code>?????r??v ???????v</code> later under certain conditions. This is not really ideal, to say the least.</p>
<p>The best thing to do is to convert the binary data to a string-based representation, e.g. a hexadecimal form or use a two-way encryption method like <a href="http://en.wikipedia.org/wiki/Base64"><cite>Base64</cite></a>. In fact, I recommend to use <cite>Base64</cite>. The drawback is, that a <cite>Base64</cite> representation uses around 35% more space than the original binary representation. For example, in <cite><abbr title="PHP Hypertext Preprocessor">PHP</abbr></cite> you would do something like this:</p>
<ol class="code">
<li><code>// Encode binary data</code></li>
<li><code>$binary = base64_encode($binary);</code></li>
<li><code>&nbsp;</code></li>
<li><code>// Decode binary data</code></li>
<li><code>$binary = base64_decode($binary);</code></li>
</ol>
<p><em>Update:</em> Changed the example data slightly to accommodate some screen readers, that require a valid feed. Thank you <cite lang="de">Jan</cite> for pointing this out.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nachtarbeiter.net/2009/04/28/storing-binary-data-inside-a-mysql-database/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

