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 = "";
$fullContent = '<meta http-equiv="content-type" content="text/html; charset=utf-8">'
+ $strWithEmoji;
$this->save($fullContent); // Function for saving into database
I don't know exact how many bytes are storing but I am trying to save only
this emoji character "" and it's storing it as 4 question marks (????).
I tried all solutions from below links, but didn't worked for me:
How to store Emoji Character in My SQL Database
UTF-8 all the way through
The ultimate emoji encoding scheme