Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't insert a unicode glyph in mysql

With this query:

UPDATE  `arg`.`arg_currency` SET  `symbol` =  '𐀤' WHERE  `arg_currency`.`id` =2 LIMIT 1 ;

I get this error:

Warning: #1366 Incorrect string value: '\xF0\x90\x80\xA4' for column 'symbol' at row 1

The column symbol was a CHAR(1) utf8_roman_ci, but I've both tried to change the collation to _general and to _unicode, and the chars to 4, but I've still got the same error.

What am I doing wrong?

(I've both tried to insert it via custom php code and via phpmyadmin)

like image 770
o0'. Avatar asked Mar 09 '11 14:03

o0'.


People also ask

How do I add a Unicode character in MySQL?

By using MySQL Workbench Alter the table of that column you want to insert unicode into. Change Collation of that column to utf8-default collation . Apply the setting and you are good to go to insert unicode.

Does MySQL support UTF 8?

MySQL supports multiple Unicode character sets: utf8mb4 : A UTF-8 encoding of the Unicode character set using one to four bytes per character. utf8mb3 : A UTF-8 encoding of the Unicode character set using one to three bytes per character.

What is encoding in MySQL?

The MySQL ENCODE() function is used for encoding a plain text string. The MySQL ENCODE() function returns a binary string which of the same size of the plain text string. The MySQL DECODE() function returns empty strings if the string passed is an empty string.


1 Answers

As @CarpeNoctumDC points out, this question explains the problem:

MySQL don't want to store unicode character

MySQL only supports characters from the basic multilingual plane (0x0000 - 0xFFFF).

Your character is out if this plane.

In your case, I would work around it by storing the character as a numeric entity. htmlentities() with the UTF-8 encoding specified should be able to entity it, for example. no, it doesn't.

This function in the User Contributed Notes of the PHP manual works for me: It converts the character into a numeric entity.

echo utf8tohtml("𐀤", true); // echoes 𐀤
like image 151
Pekka Avatar answered Sep 25 '22 14:09

Pekka