I've search around quite a bit and can't seem to find a solution to retrieving my Chinese characters from a unicode MySQL database table and displaying them properly.
I'm pretty sure it's PHP related because using the command line I can pull out stuff like this:
Code: Select all
+-------------------------+
| chinese |
+-------------------------+
| µ£¬??ô?ó??¬ì?Üä?¡öµíê
|
| µôè????ÇÖ?úí?????î
|
| ?????î
|
| ?Ç¥?¢??Ä??Ç¥
|
| ?íî?ïò????áÿ
|
| ?ü?µôç?¿ê?êåµî絿Ö
|
| ?ªé??ò?ûï?ºï
|
| ?à??¿ê?¡öµíê???µò?
|
| ?à??¿ê?äí?¡öµíê???µò?
|
| ??ò????òÅ?íî |
| ?òÅ?íî
|
| ?Ŭ?«Ç |
+-------------------------+
12 rows in set (0.00 sec)phpMyAdmin gives me the correct data when I "SELECT *" from the query window, so I guess my server is set up right (in terms of PHP config).
However, when I try to get the data in PHP on my own, all I can display is question marks, for example:
Code: Select all
<?php
header('Content-Type: text/html; charset=utf-8');
mysql_connect('localhost', 'root', 'xxx') or die(mysql_error());
mysql_select_db('blah') or die(mysql_error());
$result = mysql_query('SELECT * FROM `table`') or die(mysql_error());
while($row = mysql_fetch_assoc($result))
{
print_r($row);
}
?>Code: Select all
Array ( [order] => 15 [key] => whatever [english] => Blah blah blah blah blah blah blah blah. [chinese] => ????????????,????????? [simp_chinese] => ????????????,?????????))The same happens if I use the CodeIgniter database library (with which I have set
Code: Select all
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_unicode_ci";Some extra details:
- I'm using
Code: Select all
header('Content-Type: text/html; charset=utf-8');- My MySQL TEXT field is using the "utf8_unicode_ci" collation, on an InnoDB engine table.
- The table with the TEXT field is actually set to latin1_swedish_ci collation (I assume this is overridden by per-field settings - likewise with database-wide collation).
- FireBug tells me the Content-Type of the HTTP response is "text/html; charset=utf-8".
- I'm using this HTML header
Code: Select all
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">Code: Select all
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />- As you can see I'm not serving the document as XML (like XHTML can be), this shouldn't make a difference (?).
- I can put one of my Chinese strings into a string directly in my PHP file and echo it out fine (meaning that it can't really be anything to do with my HTML/HTTP response?).
I'm basically trying to match what phpMyAdmin is getting in the HTTP response, but don't know what this is
Code: Select all
Vary: Accept-EncodingI'm stumped; as far as I can tell I've covered everything that is suggested anywhere I read about this type of stuff.