after some research I converted the field and table collation to utf8mb4_bin
.
If I paste an emoji in the field directly through phpmyadmin, or if I write the query in the command line, it works fine.
The problem is doing it from the website.
Here is my PDO configuration:
$driver_options = [
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::MYSQL_ATTR_FOUND_ROWS => true
];
$db = new PDO('mysql:host='.$host.';dbname='.$database.';charset=utf8mb4;collation=utf8mb4_unicode_ci', $username, $password, $driver_options);
Doing it from my website, the emoticons/emojis are saved as ????
.
What else do I need to do to be able to save them correctly?
Thank you
EDIT
Solved it. If you use SET NAMES utf8
in the options
, it will overwrite the charset=utf8mb4
in the DSN, so in my case it was ultimately utf8
and not utf8mb4