How to insert emojis into Mysql database and return the same in current service

Asked

Viewed 43 times

-3

I have a messaging system. Where the client (Whatsapp) sends an emoji, and my system receives the emoji. But when the page is updated and searches the emoji in the BD to display, the emoji is displayed this way:

""

I believe they are not being saved properly in the database. Does anyone know what might be going on?

The system was made in Node, PHP and Mysql.

  • Please edit the question to limit it to a specific problem with sufficient detail to identify an appropriate answer.

1 answer

-3

You need to convert the default character setting of your tables and text fields to uft8mb4.

For example:

alter table exemploTabela charset=utf8mb4;

modify column exemploTabela varchar(255) character set utf8mb4;

I believe that already solves your problem.

Read a little more about this in this Question:

https://stackoverflow.com/questions/7814293/how-to-insert-utf-8-mb4-characteremoji-in-ios5-in-mysql

UPDATING

Alternative:

For each bank:

ALTER DATABASE
    banco_nome
    CHARACTER SET = utf8mb4
    COLLATE = utf8mb4_unicode_ci;

For each table:

ALTER TABLE
    nome_tabela
    CONVERT TO CHARACTER SET utf8mb4
    COLLATE utf8mb4_unicode_ci;

For each column:

ALTER TABLE
    nome_tabela
    CHANGE nome_coluna nome_coluna
    VARCHAR(255)
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_unicode_ci;

Try this alternative. But the problem is yes in the database encoding, which needs to be uft8mb4 to support.

  • Hello, Gabriel, I try to enter the command Modify ... but it gives a syntax error and apparently everything is right with the code. I tried to modify manually but for some reason does not update...

  • I updated the answer with an alternative, try this one to see if it can solve.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.