问题
I have an application talking to a NodeJS server via socket, that server is talking to PHP via HTTP, and that PHP is using MySQL.
When I try to insert Emojis in a text field, and save it to DB, when I get it back I see "?".
If I copy Emojis from wikipedia (for example ✒️ ❤️ 🀄️ 🈚️
) and force them to the DB, when I select them it shows ✒️ ❤️ ?️ ?️
Note: The field in DB is utf8mb4bin
.
- Why can't I store emojis directly from my device to DB?
- Why does some emojis show, while others don't?
Note: I also tried only PHP and MySQL, but with no luck.
回答1:
1.)Database : Change Database default collection as **utf8mb4 ** .
2)Table : Change Table collection as ** CHARACTER SET utf8mb4 COLLATE utf8mb4_bin **.
Query :
ALTER TABLE Tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE
utf8mb4_bin
3)Code :
insert into tablename (column1,column2,column3,column4,column5,column6,column7) values ('273','3','Hdhdhdh😜😀😊😃hzhzhzzhjzj 我爱你 ❌',49,1,'2016-09-13 08:02:29','2016-09-13 08:02:29')
4)Set utf8mb4 in database connection :
$database_connection = new mysqli($server, $user,$password,$database_name);
$database_connection->set_charset("utf8mb4");
来源:https://stackoverflow.com/questions/42279186/storing-and-showing-emojis-in-android-application-using-mysql