1

I was using PDO MySQL to insert data from PHP. What I didn't know, I had to use "SET NAMES 'utf8'" statement before making every query.

So all the input made in Simplified Chinese before making that fix (SET NAMES 'utf8' command), became something like '世家'.

I have used PHP mb_detect_encoding and it seems the encoding is still in UTF-8. Is there any way I can convert these data (the ones user entered before adding the fix) to readable Simplified Chinese characters?

Below are some examples:

(first name ; last name)

"詠昌明" ; "蔡"
"瑩書" ; "陳"
"培熙" ; "楊"
"培熙" ; "楊"
"立" ; "王"
"光凱" ; "陳"

SOLUTION:

As mentioned in the comment, the issue is actually double encoded utf-8, which can be fixed using below MySQL statement (Thanks to the answer provided in How to fix double-encoded UTF8 characters (in an utf-8 table))

UPDATE TABLE_NAME
SET FIELD_NAME = CONVERT(CAST(CONVERT(FIELD_NAME USING latin1) AS BINARY) USING utf8);

I have updated with this answer, because there might be someone who does know know about 'double encoded utf-8' :)

4
  • Can you provide an example of the text your pulling from the database?
    – Daryl Gill
    May 30, 2014 at 2:26
  • @DarylGill I have added example pulled from mysql using select query. May 30, 2014 at 3:30
  • 1
    The text that you've got there looks like double encoded UTF-8. Refer to: How to fix double-encoded UTF8 characters (in an utf-8 table) (which I've nominated this question as a duplicate of)
    – user149341
    May 30, 2014 at 3:53
  • @duskwuff Thank you :) I didn't know it was double encoded UTF-8. The solution mentioned at the url, fixed my issue. May 30, 2014 at 4:06

0

Browse other questions tagged or ask your own question.