0

I added the Emojo library including JS and CSS files. Then it starts to display on the frontend.

When I send the Emoji character via ajax. I am getting Emoji in the param request so while saving the same emoji in the database column it is saving data like (??????) characters

Here is the code that I am using to send Emoji via Ajax request::

function getAjaxrequestChat() {
       
       var message = jQuery('#chat-message').val();
        if(message == ''){
            return false;
        }
        var customername ="";
        var url= "<?php echo $this->getUrl().'test/Index/chat'?>";
        
        $.ajax({
            url: url,
            type: 'POST',
            dataType: 'json',
            data: {message:message},
            complete: function(response) {
            },
        });
   }

When I check data in the network of the browser it shows Emoji like(😃😃😃😃😁) but these emoji save in the database column show value as mentioned in the screenshot below:: enter image description here

Can you please help me to how to save the same Emoji characters that are sent through the Ajax request?

1 Answer 1

1

(MySQL) UTF-8 doesn't support all emojis. I guess you have to change the effected DB columns to "utf8mb4"

There is a good description on SE: How to store Emoji Character in My SQL Database


Just copy&paste from there, but this is important.

My answer only adds to Selvamani P answer.

You might also need to change any SET NAMES utf8 queries with SET NAMES utf8mb4. That did the trick for me.

Also, this is a great article to port your website from utf8 to utf8mb4. In particular the article makes 2 good points on indexes and repairing tables after converting them to utf8mb4:

INDEXES

When converting from utf8 to utf8mb4, the maximum length of a column or index key is unchanged in terms of bytes. Therefore, it is smaller in terms of characters, because the maximum length of a character is now four bytes instead of three. [...] The InnoDB storage engine has a maximum index length of 767 bytes, so for utf8 or utf8mb4 columns, you can index a maximum of 255 or 191 characters, respectively. If you currently have utf8 columns with indexes longer than 191 characters, you will need to index a smaller number of characters when using utf8mb4.

REPAIRING TABLES

After upgrading the MySQL server and making the necessary changes explained above, make sure to repair and optimize all databases and tables. I didn’t do this right away after upgrading (I didn’t think it was necessary, as everything seemed to work fine at first glance), and ran into some weird bugs where UPDATE statements didn’t have any effect, even though no errors were thrown.

Read more about the queries to repair tables on the article.

Btw ... this has been fixed in Magento 2.2 (https://github.com/magento/magento2/issues/12058)

This answer is by sv3n Link of answer Click

1
  • I changed all the column configuration but still Emoji saving as ??? in the column table of the database. Jan 10 at 8:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.