MySQL 中的 à 等字符无法正确显示 [英] Characters like à not displaying correctly from MySQL
问题描述
我在两台计算机的 HTML 文件中显示来自数据库的结果时出现问题.
I have a problem when displaying results from a database in an HTML file in two computers.
因此,在一台计算机中,它显示的名称如下:
So, in one computer it shows a name like this:
SAUL FRANCISCO GARCÃA RODRÃGUEZ
数据库的校对为latin1_swedish_ci
,表的校对为utf8_general_ci
.
The collation of the database is latin1_swedish_ci
and the collation of the tables is utf8_general_ci
.
在另一台计算机上显示如下(我希望它是这样):
In the other computer it shows like this (I want it to be this way):
SAUL FRANCISCO GARCÍA RODRÍGUEZ
名称列在 <select>
标签中 两个浏览器的语言是英语,Html 文件在两种环境中都相同,所以我认为这与字符集或php.ini 文件的编码
The names get listed in a <select>
tag The language of the two browsers is English and the Html file is the same on both environments so I think It has to do with the charset or encoding for the php.ini file
我尝试更改 php.ini
中的值,但没有任何变化,而且我在任何地方都找不到答案.
I have tried changing the values in php.ini
but nothing changes and I can't find the answer anywhere.
唯一的区别是,我安装了 WAMP,而在另一台计算机上,我分别安装了 Apache、MySQL 和 PHP.
The only difference is that where the results get displayed as I want I installed WAMP and in the other computer I installed Apache, MySQL and PHP separately.
抱歉,如果细节不是很丰富,但我不知道我哪里出错了.
Sorry if the details are not very informative but I have no clue where I'm going wrong.
附言在这两个数据库上,MySQL 控制台中的数据如下所示:
P.S. On both databases the data looks like this from the MySQL console:
SAUL FRANCISCO GARCÃA RODRÃGUEZ
推荐答案
编辑 php.ini
在这种情况下对您没有多大帮助.
Editing php.ini
won’t help you much in a case like this.
数据库的数据整理给您带来了什么问题?默认情况下,大多数 MySQL 为新创建的数据库安装 latin1_swedish_ci
而不是 utf8_general_ci
.
What is the data collation of the database giving you an issue? By default, most MySQL installs set latin1_swedish_ci
instead of utf8_general_ci
for newly created databases.
更改数据库的排序规则&再试一次.
Change the collation of the database & try again.
ALTER DATABASE [name of your database] CHARACTER SET utf8;
如果这是一个特定的表,排序规则可以这样更改:
If this is a specific table, the collation can be changed as so:
ALTER TABLE [name of your table] CONVERT TO CHARACTER SET utf8;
如果它是表中的特定列:
And if it is a specific column in a table:
ALTER TABLE [name of your table] MODIFY [name of your column] [other settings] CHARACTER SET utf8 COLLATE utf8_general_ci;
或者您可以导出当前数据库,使用此命令创建一个新数据库 &重新导入数据:
Or perhaps you could export the current database, create a new database with this command & reimport the data:
CREATE DATABASE [name of your database] CHARACTER SET utf8 COLLATE utf8_general_ci;
如果您想对出现问题的机器上的 MySQL 安装进行永久更改,请去编辑 my.cnf
.以下内容会将整个链设置为 UTF-8:
And if you want to make a permanent change to the MySQL install on the machine giving you an issue, go and edit my.cnf
. The following would set the whole chain to UTF-8:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
这篇关于MySQL 中的 Ã 等字符无法正确显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!