MySQL UTF8 data not displaying properly

I want all the data in MySQL to be encoded in UTF8. I installed all character sets and collation for UTF8 for database, tables and columns. Before anything is written to the database, I use mb_detect_encoding in PHP to check if it is UTF8. Thus, I believe that all data is encoded in UTF8.

However, here is the problem: take this word Ríkarðsdóttir, it displays correctly when prompted from the database and displays through PHP on a UTF8-encoded web page. If I request the same entry through phpMyAdmin, I get RÃkarà ° sdóttir. The same is true if I use the MySQL command line.

Running SHOW VARIABLES returns to me: character_set_client utf8, character_set_connection utf8, character_set_database utf8, character_set_filesystem binary, character_set_results utf8, character_set_server latin1, character_set_system utf8 

Only the server is latin1, and I am on a shared hosting site and do not believe that I can change this. Could this be a problem?

Here's what I don’t understand: why is my UTF8 webpage correctly displaying Ríkarðsdóttir, but the phpMyAdmin webpage with UTF8 encoding is displaying it as RÃkarà ° sdóttir? Is the data not really UTF8 encoded or does the database not believe it? What needs to be done to fix this?

+4
source share
1 answer

Try running this query immediately after connecting:

 SET NAMES UTF8 

Your database should store data as UTF8, and your web page title should also have a UTF8 declaration, but your database connection should also use UTF8. You can run this on the command line and / or through PHPMyAdmin. All communications after this “request” will be encoded by UTF8.

+3
source

All Articles