Search code examples
mysqlcodeigniterunicodeemojiutf8mb4

How do I store unicode emoji to MYSQL in CodeIgniter


I'm using codeigniter and trying to save 🚚 to a MYSQL database table

The error i'm getting is

Incorrect string value: '\xF0\x9F\x9A\x9A' for column 'post'

Solution

  • 1) Ensure you're using MYSQL 5.5 only then will you be able to change the collation to utf8mb4_something

    2) Ensure table columns that are going to receive emoji have their collation set to utf8mb4_something

    3) Edit your database.php config file

    $db['default']['char_set'] = 'utf8mb4';
    $db['default']['dbcollat'] = 'utf8mb4_unicode_ci';