PhpMyAdmin错误地显示字符

时间:2012-12-09 21:07:34

标签: mysql character-encoding phpmyadmin

当我尝试浏览表格或进行查询时,PhpMyAdmin无法正确显示字符(或者我希望它们显示的方式)。但是,如果' SET NAMES LATIN1;'包含在查询之前。此外,使用命令行客户端时,一切都在服务器端正确显示。我试图在phpMyAdmin首页上将MySQL连接排序规则设置更改为latin1,但它没有任何效果。我不明白为什么会这样。这是由通信问题还是双重编码引起的?

MySql服务器设置(来自命令行客户端):

+--------------------------+----------------------------+
| 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       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+

+----------------------+-------------------+
| Variable_name        | Value             |
+----------------------+-------------------+
| collation_connection | latin1_swedish_ci |
| collation_database   | latin1_swedish_ci |
| collation_server     | latin1_swedish_ci |
+----------------------+-------------------+

1 个答案:

答案 0 :(得分:0)

在查询上方添加ini_set('default_charset', 'UTF-8');

或者,如果您使用的是mysqli:

$dbc = mysqli_connect($host, $user, $password, $database)
    or die('Error connecting to the database');

if (!mysqli_set_charset($dbc, "utf8")) {
    printf("Error loading character set utf8: %s\n", mysqli_error($dbc));
} else {
    printf("Current character set: %s\n", mysqli_character_set_name($dbc));
}