phpmyadmin display utf8

By ET

Took me a whole afternoon to figure it out.

MySQL used non-utf-8 encoding, so when I use phpmyadmin to interpret it, the returned result is messed up.

mysql> show variables like ‘character_set%’;
+————————–+——————————–+
| Variable_name | Value |
+————————–+——————————–+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | \mysql\share\charsets\ |
+————————–+——————————–+
8 rows in set (0.00 sec)

mysql> show variables like ‘collation%’;
+———————-+——————-+
| Variable_name | Value |
+———————-+——————-+
| collation_connection | latin1_swedish_ci |
| collation_database | latin1_general_ci |
| collation_server | latin1_general_ci |
+———————-+——————-+
3 rows in set (0.00 sec)

I wrote a program to query the DB and used the following code to check if the characters are indeed utf-8:

use strict;
use Encode;
my $iftest=1;
my $ifpause=1;
use DBI;
my  $conn = DBI->connect     ("DBI:mysql:ki","","")     or die("Cannot connect: $DBI::errstr");
$conn->{RaiseError} = 0;
my $sql;
my $query;
my $row;
my $id=1;
$sql=qq(select * from categorylinks );
$query = $conn->prepare($sql);
$query->execute 		or print("n[Select ID]Error executing SQL statement! $DBI::errstrn”);
while ($row = $query->fetchrow_arrayref){ 		my $line=@$row[1];
$line=decode(”utf8″,$line);
$line=encode(”gbk”,$line);
print “$linen”;
}  $conn->disconnect;
exit;

Turned out that the output are correct.

By phpmyadmin still outputs messy code for Chinese, so I modified the following file

/phpMyAdmin/libraries/select_lang.lib.php

Under “// MySQL charsets ma”
Changed from
‘utf-8′ => ‘utf8′,
To
‘utf-8′ => ‘latin1′,
Voila, it worked

  1. 10
    Ioannis Says:

    WoW! It does work indeed!!!

    All the encodings (on the php, database, table and collations level) are correct (utf8) but the result in the phpmyadmin (phpMyAdmin - 2.11.4) are not displayed correctly. When ‘utf-8? => ‘latin1? it fixed the display problem (Note: the web page encoding still correctly is utf-8 - Strange).
    Does anyone knows why is this happening ? Should we report it as a bug ?

    Thanx all

  2. 9
    Antonio Says:

    Thank you very much. I was going crazy with this. I spent hours trying to fix this. Thank you very much.

  3. 8
    ET Says:

    It has to do with the internal storage of the characters. I guess this works as a quick fix, it does not mean the database is configured properly.

  4. 7
    a man Says:

    wow it work! Thanks a lot.
    ——————————————–
    but I am confused.

    ‘utf-8′ => ‘utf8′, It’s correct,but messed up the display result.
    ‘utf-8′ => ‘latin1′ It’s is uncorrect,but fixed the problem.

    WHAT THE HELL WAS THAT

  5. 6
    HP Says:

    Many thanks, this solved my problem!

  6. 5
    Piotras Says:

    Thank you. It works for lithuanian language too.

  7. 4
    aw tan Says:

    if the purpose is just for phpmyadmin to display chinese utf8 chars correctly, you can set charset to utf8 either at db, table, or column level, such as

    create table foo (name varchar(255) set charset utf-8); OR

    create table foo (name varchar(255)) set charset utf-8

    I have tried it. phpmyadmin does display the chinese characters correctly.

    I have a different problem — those utf8 chars don’t show up correctly in php applications.

  8. 3
    Markus Says:

    Thanks, this was a solution for my problem too!

  9. 2
    ET Says:

    Cool. :-)

  10. 1
    cory Says:

    This worked for me. Great find, thanks.

Leave a Reply


BlogTimer
You are visitor number several since September 1, 2001

Copyright Xiaoquan (Michael) Zhang, 2004-2007. All rights reserved.
All trademarks property of their owners.