0

Possible Duplicate:
UTF-8 all the way through

What my program does, is that on the client side, with the browser's encoding being UTF-8, the client types in some chinese into a textbox. This text is then transferred via jQuery $.post to my server side. On the server, it is inserted into the database. When I first put it in, it became unreadable text. Next time, I tried to see where it went wrong, and outputted the server copy, and found that it was perfectly fine (perfectly readable Chinese text). So then I figured the problem must occur when the text was inserted into the database, somewhere in the SQL statement.

Is there a way to fix this error?

Community
  • 1
  • 1
Lucas
  • 16,930
  • 31
  • 110
  • 182
  • 1
    Please see: [UTF-8 all the way through](http://stackoverflow.com/questions/279170/utf-8-all-the-way-through) - Also: http://www.joelonsoftware.com/articles/Unicode.html; http://kunststube.net/encoding/; – hakre Nov 20 '12 at 10:16
  • There is no Chinese text, only bytes. First you need to ensure that your bytes are right. Then you need to make sure that you're decoding them properly for display. The database doesn't actually store little pictures in .gif format y'know :P – Lightness Races in Orbit Nov 20 '12 at 10:22

3 Answers3

1

You have to set the charset of your DB to UTF-8 as well.

Sudar
  • 18,954
  • 30
  • 85
  • 131
1

It happens because you have to set the charset to UTF too. If you have it set already then I assume you are working under windows and are trying to see the text in the MysqlWorkbench or something like that? I know this because I am chinese and used some chinese software and had the weird symbols everywhere xD.

Then you need to configure you OS to display those characters, in the control panel -> language and regional options or the keyboard options, sorry I don't remember the exact place cos I'm on a mac in the workplace.

It happens that the browsers can display those characters but the OS won't display those unless you set it.

aleation
  • 4,796
  • 1
  • 21
  • 35
0

Check this:

Specify character set to utf8 for the column in which you are saving unicode values.

Use VARCHAR(250) CHARACTER SET utf8 instead of VARCHAR(250)

MySQL and Unicode

ALTER TABLE tableName MODIFY ColumnName VARCHAR(250) CHARACTER SET utf8

How to support full Unicode in MySQL databases

Kapil Khandelwal
  • 15,958
  • 2
  • 45
  • 52