Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL database language problem 1

Status
Not open for further replies.

zyzjacky

Programmer
Jan 19, 2006
76
MT
Again! I don't know why. I got rubbish words!
the mysql charset is UTF-8 Unicode (utf8), collation is utf-8_general_ci.database type is MyISAM. collation utf8_bin. the problem is when i save data to char field type, everything is ok, chinese can show correctly. but if the field type is text, then it saves as rubbish meanless words. How to solve this problem? Thanks!
 
couple of ideas:

1. always use varchar instead of char. this is because mysql can adapt the size of a varchar field dynamically whereas a char(20) field type it must reserve the right number of bytes independendent on how you use the column.
2. for lengths over 255 you'll want text or blob (as you are using).
3. be aware that the charset used for data storage is not necessarily the same charset as used for the communication of data between the server and client, or the same charset used for the display of data. to start with issue a query after you connect to the server in the form
Code:
SET NAMES 'utf8';
[it should stick for the entire connection]
or even better, to the actual charset that you are working with (chinese from memory)
4. if still stuck (or anyway) read the mysql faq on charset issues with 3bytes characters. for mysql5 find it at
 
thank you! I have solved the problem. because i am using a wysiwyg editor, and it post data in utf-8, so i get some crazy text. anyway, it works now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top