This question already has an answer here:
I am trying to save emoji symbol to database record but each time it's not saving properly.
I've referred this How to store Emoji Character in My SQL Database but still not working.
As per solution on above question, I tried to change the character set from utf8 to utf8mb4 and collation from utf8mb4_bin.
I tried everything like resetting to default and then changing it in the database table. I tried utf8mb4_unicode_ci, utf8_unicode_ci and utf8mb4_bin but it's not working.
I am using MySQL 5.6 version. And I am changing the collation with below query
alter table `users` convert to character set utf8mb4 collate utf8mb4_bin;
The above code is working fine, it's changing the UTF type in database. But emoji is not saving properly it's saving as question marks (????)
Below is my database table structure example:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'System generated id used for uniqueness',
`introduction` longtext COLLATE utf8mb4_bin,
`other_details` longtext COLLATE utf8mb4_bin,
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin AUTO_INCREMENT=41213 ;
To save emoji using below PHP code:
$dom = new DOMDocument('1.0', 'UTF-8');
$strWithEmoji = "