views:

24

answers:

2

I'm making small module/plugin for my future CMS/Framework. I wanted it from begining to be with multi-language support.

  • I set my new database to utf8_unicode_ci (I read that it is more accurate, then utf8_general_ci)
  • Set my files to UTF-8 without BOM
  • Every page has in head Content-Type: text/html; charset=utf8

When I register new user new record is added to user table. I tried to register user with russian nickname. When I inserted it to form it was fine. Added record to table. Signed in and showed greetings fine in russian too. But when I looked at the record in table the nickname was some gibberish characters. I tried all encodings in browser. Nothing helped.


UPD: I even tried to view data with SQLyog. Shows same as phpMyAdmin.

Small screenshot of what I mean alt text


Could anyone explain to me, what might be the problem?

A: 

Here's an earlier answer of mine about the same problem, try that: http://stackoverflow.com/questions/3021769/how-to-display-a-mysql-table-data-in-another-language-properly-in-php/3021908#3021908

robertbasic
Did I understand correctly, that you are describing how to display characters in any language properly in database view. Since on webpage everything is fine. Problem is when I view the records through phpMyAdmin.
Eugene
@Eugene as a matter of fact, phpMyAdmin is just another webpage ;)
Col. Shrapnel
@Col. Shrapnel in update I mentioned, that I also tried an application SQLyog to view the data.
Eugene
A: 

Every page has in head Content-Type: text/html; charset=utf8

is it meta tag or HTTP header? must be a latter one.

and you have to run SET NAMES utf8 query every time you connect to the database in your PHP scripts

Col. Shrapnel
It's meta `<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />`Do you mean, that after I connect and select database I should execute query `SET NAMES utf8;`
Eugene
yes, I mean you should execute query SET NAMES utf8 every time you connect and selecte database. Just add it to your connect code. And Content-Type: should be sent using header() function
Col. Shrapnel
Bu how does it change what I see in my database. Doesn't it change only what I get from there. And data on the webpage is fine. It shows it self incorrectly in database. I'll add a small screenshot.
Eugene
1. you have never seen your database. But just another webpage. 2. It does change what you can see in your database by telling it NOT to recode incoming symbols. Your current data is spoiled and should be deleted.
Col. Shrapnel
@Col. Shrapnel, great. Thanks. After I added `SET NAMES utf8` to my SQL class as query I tried to add new user with russian nickname and everything is view fine now. Thank you very much. That was quite a pain in the as* for a while.
Eugene