0

I'am trying to add unicode icons to my website SEO title/meta and for some reason it will not accept some icons. My site is UTF-8. Im saving it in my database as utf8_general_ci.

When i add the icon it will return as ???? https://emojipedia.org/heavy-dollar-sign/

When I add the icon ✔️ it will add the ✔️ in the title. https://emojipedia.org/check-mark/

Is there an reason for this or is this normal?

user759235
  • 2,147
  • 3
  • 39
  • 77
  • Good pointer, did see that if i change the type to BLOB it will save the icons. Thanks – user759235 Jul 27 '20 at 08:24
  • I reopened this question because the main Answers in the proposed dup ( https://stackoverflow.com/questions/39463134/how-to-store-emoji-character-in-mysql-database ) failed to suggest the one thing that was needed to fix the problem. – Rick James Jul 27 '20 at 18:01
  • Changing to `BLOB`, though it will work, is simply sweeping the problem under the rug. It is solvable with `TEXT` and `utf8mb4`. – Rick James Jul 27 '20 at 18:09

1 Answers1

0

"✔️" is a 3-byte Emoji; "" takes 4 bytes. So the problem is that CHARACTER SET utf8 needs to be changed to CHARACTER SET utf8mb4.

The solution is to either

  • Provide utf8mb4 in the connection parameters`. This action varies with the client (Java/PHP/...).
  • Add SET NAMES utf8mb4 to the code right after connecting.

If these are not specific enough, search for where you have utf8 and it could be utf8mb4. (Note: I am not saying UTF-8, which is the non-MySQL equivalent of utf8mb4.)

More discussion: Trouble with UTF-8 characters; what I see is not what I stored

Technically the checkmark takes 6 bytes -- two 3-byte characters: hex E29C94 EFB88F. So it worked fine with utf8. However the dollar sign needs 4 bytes: F09F92B2, so it could not be represented in utf8, only in utf8mb4. The failure was shown via 4 question marks.

Rick James
  • 135,179
  • 13
  • 127
  • 222