Emojis replaced by question marks

corentin.bc Posted messages 385 Registration date   Status Membre Last intervention   -  
jordane45 Posted messages 30426 Registration date   Status Modérateur Last intervention   -
Good evening,
I have an issue with my website, all the emojis are replaced by question marks "?".
I have done quite a bit of research, and the solution found is to set the table to utf8mb4.
My database is in utf8mb4-unicode_ci.
My database connection code is as follows:

try {$bdd = new PDO('mysql:host=localhost;dbname=apfr;charset=utf8mb4', '', '',
array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET character_set_results = 'utf8mb4', character_set_client = 'utf8mb4', character_set_connection = 'utf8mb4', character_set_database = 'utf8mb4', character_set_server = 'utf8mb4'"));}
catch(Exception $e) {die('Error !');}

despite all this, the problem persists.
Do you have any idea how I can get rid of the issue once and for all?
Thank you in advance.

1 réponse

jordane45 Posted messages 30426 Registration date   Status Modérateur Last intervention   4 830
 
Hello,
You can specify the charset directly in the connection string (the dsn)
 $dsn = 'mysql:host=localhost;dbname=apfr;port=3306;charset=utf8mb4'; 

The other solution, a bit like yours but with the collate added in the MYSQL_ATTR_INIT_COMMAND
 $bdd =new PDO( 'mysql:host=localhost;dbname=apfr;port=3306;charset=utf8mb4', 'your-username', 'your-password', array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => false, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci" ) ); 

Don't forget to check the encoding declared in your files as well as that of your files.
I invite you to read this: https://forums.commentcamarche.net/forum/affich-37584944-php-html-caracteres-accentues-et-l-utf8

--
Best regards,
Jordane
0