<?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>Elzo Valugi &#187; mysqli</title>
	<atom:link href="http://blog.valugi.ro/tag/mysqli/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.valugi.ro</link>
	<description>professional websurfing</description>
	<lastBuildDate>Sun, 15 Aug 2010 06:34:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PDO charset problems</title>
		<link>http://blog.valugi.ro/2008/08/28/pdo_charset_problem/</link>
		<comments>http://blog.valugi.ro/2008/08/28/pdo_charset_problem/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 10:29:36 +0000</pubDate>
		<dc:creator>elzo valugi</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[charset]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysqli]]></category>
		<category><![CDATA[pdo]]></category>

		<guid isPermaLink="false">http://blog.valugi.ro/?p=195</guid>
		<description><![CDATA[These are the problems of the world before PHP6. Soon to be forgotten. I was working in my application with different charsets, like slavic (cyrillic), japanese or arabic and in the database all was peachy and the localized information was stored correctly under utf8_unicode_ci encoding. The problem was that the php received and printed wrong [...]]]></description>
			<content:encoded><![CDATA[<p>These are the problems of the world before PHP6. Soon to be forgotten.<br />
I was working in my application with different charsets, like slavic (cyrillic), japanese or arabic and in the database all was peachy and the localized information was stored correctly under <em>utf8_unicode_ci</em> encoding. The problem was that the php received and printed wrong information, like question marks or squares or strange chars, and this usually happens when the headers are not set properly which was not the case.</p>
<p>I am using PDO as the abstraction layer in this project, and it appears that you have to specificly state your pdo connection what type of encoding you want for transfer.</p>
<pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New'; overflow-x: auto; overflow-y: auto; width: auto; max-height: 600px; background-position: initial initial; background-repeat: initial initial; padding: 5px; border: 0px initial initial;">$db-&gt;query('SET NAMES UTF8');</pre>
<p>For mysqli</p>
<pre style="margin-top: 0px; margin-right: 0px; margin-bottom: 10px; margin-left: 0px; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New'; overflow-x: auto; overflow-y: auto; width: auto; max-height: 600px; background-position: initial initial; background-repeat: initial initial; padding: 5px; border: 0px initial initial;"><code style="font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: #eeeeee; font-family: Consolas, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New'; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;"><span style="font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">$mysqli</span><span style="font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">-&gt;</span><span style="font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">query</span><span style="font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">(</span><span style="font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: maroon; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">"SET NAMES 'utf8'"</span><span style="font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: transparent; color: black; background-position: initial initial; background-repeat: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">);</span></code></pre>
<p>This simple line in the connection part solve it all. Actually this is not even a PDO thing, is a mySQL thing; in this case we instruct the server and the client what encoding to use in the communication.</p>
<p>This is more a workaround, because the communication should be done depending on the _default-character-set_ variable from mysql ini file. There are several bugs related with this problem in php and mysql bug zoo.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.valugi.ro/2008/08/28/pdo_charset_problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
