php & msql – emoji


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

Leave a Reply

Your email address will not be published. Required fields are marked *