www.webdeveloper.com
Results 1 to 10 of 10

Thread: Not support utf-8: Where is the problem?

  1. #1
    Join Date
    Feb 2011
    Posts
    81

    Not support utf-8: Where is the problem?

    Hi there,

    My web server on Windows 7 displays all utf-8 chars well but not on Linux even both MySQL database is created with "CHARACTER SET utf8 COLLATE utf8_unicode_ci", and all php pages are created with utf-8. Where is the problem pn Linux: Apache configuration or php5 configuration? Both use Apache as web server.

    Thanks,

  2. #2
    Join Date
    Feb 2011
    Posts
    81
    I think this would be easy for those who know well of Apache and php, am I right?

    Thanks,

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,359
    Here's most of what I know on the subject: http://www.charles-reace.com/blog/20...php-and-mysql/
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    Feb 2011
    Posts
    81
    Thanks, NogDog, a nice link. I'll try it out and let you know, have a nice day,

  5. #5
    Join Date
    Feb 2011
    Posts
    81
    For some reason, it doesn't work out. In the code, PDO is used as below:

    new PDO("mysql:host={$dbhost};dbname={$db};charset=utf8",$userid, $pw,
    array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

    Also, I check mysql, all setting is utf8 as below. Use Aqua Data Studio to display, it doesn't show correct, even correct by connecting to mysql on Windows. More strange is another page using mysqli displaying the content correct. Do this mean the problem is PDO?
    Before the string is sent to mysql, it's handled by addslashes function.

    Thanks,
    mysql> show variables like 'char%';
    +--------------------------+----------------------------+
    | Variable_name | Value |
    +--------------------------+----------------------------+
    | character_set_client | utf8 |
    | character_set_connection | utf8 |
    | character_set_database | utf8 |
    | character_set_filesystem | binary |
    | character_set_results | utf8 |
    | character_set_server | utf8 |
    | character_set_system | utf8 |
    | character_sets_dir | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)

    mysql> show variables like 'collation%';
    +----------------------+-----------------+
    | Variable_name | Value |
    +----------------------+-----------------+
    | collation_connection | utf8_general_ci |
    | collation_database | utf8_unicode_ci |
    | collation_server | utf8_unicode_ci |
    +----------------------+-----------------+
    Last edited by wow; 03-13-2013 at 08:09 PM.

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,359
    Have you tried doing the SET NAMES 'utf8' COLLATE 'utf8_unicode_ci' query before doing any other queries (read or write)?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  7. #7
    Join Date
    Feb 2011
    Posts
    81
    It's proved the problem is PHP MySQL PDO module: in the same php page, both mysqli and PDO are used in almost the same way, the same query by mysqli displays result properly, but not the one with PDO:
    mysqli: displays - This is a 鮓lunch menu
    PDO: displays -This is a “lunch menu

    In Windows platform (both PHP and MySQL installed on Windows), both are the same.

    Even PDO constructs the connection with utf8 as below:
    $pdo = new PDO("mysql:host={$dbhost};dbname={$db};charset=utf8",$userid, $pw,
    array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

    Please help where is problem the above pdo statement. I'm told PDO has more advantage.

    Thanks,
    Last edited by wow; 03-13-2013 at 09:33 PM.

  8. #8
    Join Date
    Feb 2011
    Posts
    81
    Thanks NogDog, it's done:

    $anum = $pdo->exec("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");

  9. #9
    Join Date
    Feb 2011
    Posts
    81
    Does this mean I have to give up PDO and turn to use mysqli? Is this a bug of mysql PDO?

    Thanks,
    Last edited by wow; 03-14-2013 at 04:11 PM.

  10. #10
    Join Date
    Feb 2011
    Posts
    81
    Quote Originally Posted by NogDog View Post
    Have you tried doing the SET NAMES 'utf8' COLLATE 'utf8_unicode_ci' query before doing any other queries (read or write)?
    Yes, I did right away after the connection is got with:
    $anum = $pdo->exec("SET NAMES 'utf8' COLLATE 'utf8_unicode_ci'");

    Even it's not needed for my mysql configuration, it's a unnecesary step, I think, but, just in case.

    Thanks,
    Last edited by wow; 03-14-2013 at 04:10 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles