Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

php - Characters like à not displaying correctly from MySQL

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

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

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

I have tried changing the values in php.ini but nothing changes and I can't find the answer anywhere.

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.

P.S. On both databases the data looks like this from the MySQL console:

SAUL FRANCISCO GARC?A RODR?GUEZ
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Editing php.ini won’t help you much in a case like this.

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;

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...