F
F
Fedi4kin2016-02-01 19:36:41
MySQL
Fedi4kin, 2016-02-01 19:36:41

mysql encoding problems ERROR 1366 (HY000) at line 1: Incorrect string value. How to fix?

The error looks like this:

│ERROR 1366 (HY000) at line 1: Incorrect string value: '\xF0\x9F\x91\x91\xD0\x98...' for column 'name' at row 1

It occurs when the name of the community enters the database, using the symbols vk.
https://vk.com/public46112949
I tried to change the encoding in the table (utf8mb4 only partially helps) and different combinations of methods from the Internet. Did not help.
Can you tell me how to remove these characters?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Назар Мокринский, 2016-02-01
@nazarpc

Firstly, uft8mb4 solves the problem entirely, just rechecked.
It all depends on how you insert those characters. Using prepared statements or manually calling mysqli_real_escape_string() (if it's PHP) you won't have any problems with these characters.
You can also remove characters, the first thing that comes to mind is to use the mb_* functions to determine the length of the string, then iterate character by character and get the character code. If the number is more than 2 bytes - delete.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question