MySQL and utf8 problems

I am creating a multilingual Web application. I use MySQL 5.1.11 on MS Windows XP SP2 and Apache 2 and PHP 5.
I have marked all my Web pages with meta tags for utf8, I set utf8 as default charset in my.ini file and I define utf8 fro each MySQL table. Everything seems to work fine while I work with my db through a Web browser. But if I open a table in MySQL Administartor or SQLyog or Aqua Data Studio, I see that every field with text contains unrecognizable symbols! And, if I put a unique index on this field and try input duplicates through a web browser, I receive that Error Duplicate entry message with the same unrecognizable symbols. At first I thought that maybe something gets converted strangely while going through a web browser and php engine, but if I use php to save the same text in the simple file, it is correct.
If I enter the text in the db with any GUI tool, I get some language-specific simbols corrupted, they become like "?" and then my web browser displays them as "?" too.
As far as I have seen simple Unicode files my experience is that only language-specific chars get coded with more than 1 byte. But it seems that MySQL codes even normal latin symbols with more than one byte because the text "MySQL is great" becomes "aeiourgklnc

Comments

  • Greetings.

    You may search in php.net for the iconv function sets. These are to work with encoding. The syntax for iconv() is:
    [code]$string = iconv($inputencoding, $newencoding, $var);[/code]
    Also, double-check your php.ini. Since PHP4, php.ini contains encoding information too. If you have a "default_charset" declared, that may be your problem. If you don't have access to php.ini (shared hosting environment), you can use:
    [code]print_r(iconv_get_encoding());[/code]
    ... to determine what encoding is used. Or:
    [code]ini_set("default_charset","UTF-8");[/code]
    ... to set PHP encoding to UTF-8.

    Cheers.

    Francis
  • I forgot, if you use XHTML, don't forget to declare XML encoding type to UTF-8 too. :P
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion