• Saving Emoticons/Unicode character to a MySQL Database, or how I discover that mysql “utf8” engine was not enough and I used utf8mb4

    Saving Emoticons/Unicode from Twitter to a MySQL Database

    The last couple of days I’ve been developing a little app that imports Twitter feeds and saves tweets to a MySQL database; however, I quickly hit an issue where certain tweets would not save. MySQL was returning the error message ‘SQLSTATE[HY000]: General error: 1366 Incorrect string value’. Looking at the specific tweets causing the database to throw the error I noticed that they contained emoticons.

    The Problem

    I was using utf8 encoding in MySQL which I thought (wrongly) could represent all unicode characters.

    The unicodes for emoticons are fully supported by the UTF-8 encoding; however, MySQL’s utf8 does not! To save emoticons to a MySQL database we need to use utf8mb4.

    The difference between MySQL’s utf8 and (...)