Webmail Error due to Emoji A site I'm working on came across the following error in Drupal based on the addition of an emoji flex graphic put into the form field. 

PDOException: SQLSTATE[HY000]: General error: 1366 Incorrect string value: ‘\xF0\x9F\x92\xAA e…’ for column ‘data’ at row 1: INSERT INTO {webform_submitted_data} (mid, sid, cid, no, data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder3, :db_insert_placeholder_4); 
     Array ([:db_insert_placeholder_0] =&gt; 64
    [:db_insert_placeholder_1] =&gt; 10
    [:db_insert_placeholder_2] =&gt; 11
    [:db_insert_placeholder_3] =&gt; 0
    [:db_insert_placeholder_4] =&gt; Need multiple 250 ton Jacks, force not strong [AndroidFlexEmoji] enough) in drupal_write_record() (line 7239 of E:\webserver\Inetpub\wwwroot\includes\common.inc).


After digging around for a while on this site and others, I came across the following suggestion:

[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

I'm not 100% sure if this will fix the issue I'm having, however, I'm not sure where to alter this to test it. The link below states that in Drupal you can find it under /includes/database/mysql/database.inc around line 53 but no luck. 

Reference link: How can I remove emoji from all user input?
Any clarification would be great.
Do not hack the core (change any of the files in the initial Drupal download) unless you are using a patch in the issues queue or making one for a registered issue, /includes is part of that core.


The reason for this is that you will not be able to reliably upgrade your Drupal site as new versions are released and it is very important to keep it updated for security reasons.


Do always test new things on a development copy of your site, never on your production site (at least not after launch).


That being said, the best part of the answer you referenced is:


  All in all, I would prefer to just switch my MySQL to utf8mb4 charset, that supports all utf8 as it ought to be supported. You need MySQL 5.5.3 or greater to do this.


To elaborate:

MySQL allows various different encodings in its storage engine.  Latin1 (often the default) stores all of the data in one way and allows a limited set of characters.  UTF8 is a much larger library of characters.  Characters that exist in UTF8 that don't exist in Latin1 (for example) will make your database cry because it doesn't know how to read them.

The solution is to tell your database to use UTF8 instead of Latin1.

There are instructions online for doing this in-place but I personally prefer to do a mysqldump and import the database into a fresh database that has been specifically set to use UTF8, then tell Drupal where to find the new database.

As Molot said in his answer, you need MySQL 5.5.3 or higher to use UTF8, so you may need to upgrade your version of MySQL.  If you're on shared hosting this could be difficult, you should be able to see your MySQL version in CPanel or Plesk, otherwise ask your hosting provider for support.