Archive for July, 2008

h1

CJK Characters Displaying Incorrectly

July 8, 2008

When I tried retrieving something with CJK characters from my database (e.g. こんにちは!), they displayed as ???? characters. But when I checked the actual database, the characters were written as in CJK characters (こんにちは!). I looked for a solution and I found out that I need to add this line below my database connection:

mysql_query("SET NAMES 'utf8'");

So, it would probably look something like this:

$dbconnect = mysql_connect('localhost', 'username', 'password');
if (!$dbconnect) die(mysql_error());
mysql_select_db('dbname');

mysql_query(“SET NAMES ‘utf8′”);

An ultra short summary explanation for this, according to that long article I read, MSQL databases tend to have a latin1 charset set as a default and it needs to be changed to utf8 to make it work.

Another thing is that in your database table’s Collation, you should find a utf8_general_ci instead of a latin1_swedish_ci one.

PS: I love you google!