While I was trying to add some emojis via CodeIgniter to a MySQL database/table, I got the following error:
Incorrect string value: '\xF0\x9F\x98\x94\xE2\x80...' for column '
I had to change the table’s field collation to utf8mb4_general_ci.
Every time we make a select on the DB, previously we need to SET NAMES and SET CHARACTER SET – i’v tried to do it on database configurations (application/config/database.php) but it didn’t worked.
$this->db->query("SET NAMES 'utf8mb4'"); $this->db->query("SET CHARACTER SET utf8mb4");
The do the select to the table with the fields that have emojis.
NOTE! if we are displaying the *content* on a html tag that has google webfonts defined on it emojis won’t be displayed.
OK! It should work! 🙂
More readings
- https://mathiasbynens.be/notes/mysql-utf8mb4#character-sets
- http://stackoverflow.com/questions/31812502/inserting-emoji-smartphones-in-mysql-database-with-php
- http://stackoverflow.com/questions/9509668/iphone-emoticons-insert-into-mysql-but-become-blank-value
- http://apps.timwhitlock.info/emoji/tables/unicode