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' :)

Community
  • 1
  • 1
  • Can you provide an example of the text your pulling from the database? – Daryl Gill May 30 '14 at 02:26
  • @DarylGill I have added example pulled from mysql using select query. – Habib Ullah Bahar May 30 '14 at 03: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)](http://stackoverflow.com/questions/11436594/how-to-fix-double-encoded-utf8-characters-in-an-utf-8-table) (which I've nominated this question as a duplicate of) –  May 30 '14 at 03:53
  • @duskwuff Thank you :) I didn't know it was double encoded UTF-8. The solution mentioned at the url, fixed my issue. – Habib Ullah Bahar May 30 '14 at 04:06

0 Answers0