If accented text shows up as ??? or as é instead of é, the database, the connection and the page are not speaking the same character set. The rule that fixes almost everything is to use utf8mb4 in all three: in the database, in the application’s connection and in the page (<meta charset="utf-8">).
The three places the fault can be
| Where |
How you see it |
How to fix it |
| The page |
Accents break even when the database is right. |
Declare utf-8 in the page and save the file as UTF-8. |
| The connection |
??? or é appear only when the text passes through the application. |
Ask for utf8mb4 when connecting. In PDO, charset=utf8mb4 in the DSN. In mysqli, set_charset('utf8mb4'). See the PHP example. |
| The database or the table |
Saving emoji fails, or characters are lost. |
Convert to utf8mb4 (below). |
Converting a database and its tables
| 2 |
On the phpMyAdmin SQL tab, for the database:ALTER DATABASE account_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
| 3 |
For each table:ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
|
| 4 |
In the application ask for utf8mb4 on the connection. In WordPress, DB_CHARSET in wp-config.php should be utf8mb4.
|
|
| 5 |
Test by saving a text with an accent and an emoji, and reading it back.
|
|
|
Converting does not recover what is already lost. If the database stored “???” in place of the letters, those letters are gone: converting does not bring them back. Only an old copy or retyping the text will. And when the text came out as é (not ???), you have a double-encoding problem, which needs care: ask for help before touching it.
|
| Term |
What it is |
utf8mb4 |
The full character set: accents, alphabets, emoji. The one to use. |
utf8 (or utf8mb3) |
A shorter version that cannot store emoji or some other characters. |
| Collation |
The rule for comparing and sorting. utf8mb4_unicode_ci is a safe choice here. |
utf8mb4_0900_ai_ci |
A MySQL 8 collation. MariaDB does not know it. See MySQL or MariaDB. |
How to see what the database has
On the phpMyAdmin SQL tab, SHOW CREATE TABLE table_name; shows the table’s character set and collation, and SHOW VARIABLES LIKE 'character_set%'; shows the values of the connection you are using. If the table says utf8mb4 and the text comes out wrong, the fault is in the connection or the page. If the table says latin1 and the text has emoji, that is the problem. Finding the right place before converting saves you from touching what was not broken.
|
Accents still broken after all this? Tell us the page address and what the database shows in phpMyAdmin and we will look.
Open a support ticket
|
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from $6.59/mo (3-year plan, with coupon) See plans |