Tjorriemorrie
Tjorriemorrie

Reputation: 17282

Doctrine2 not saving utf-8

In my Symfony 2 app my Doctrine charset is set to UTF8.

I have this string which starts with 🌹 Using mb_detect_encoding it's UTF-8.

But saving it into a text field on a Doctrine entity gives me the following error:

SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\\xF0\\x9F\\x8C\\xB9 h...' for column 'text' at row 1",

What the hell is happening here?

Upvotes: 4

Views: 2147

Answers (1)

Danack
Danack

Reputation: 25701

The error message tells you what is happening. The database engine is unable to store the string value \xF0\x9F\x8C\xB9 in the database.

That appears to be the character U+1F339 ROSE which is in the supplementary multi-lingual plane and takes 4 bytes to store.

MySQL UTF8 doesn't actually support all of UTF8, and basically doesn't work at all for 4 byte characters. See this answer for suggestions on how to fix it but basically you need to switch to use the 'utf8mb4' charset everywhere with the collation 'utf8mb4_unicode_ci' if you want to store these characters.

Upvotes: 6

Related Questions