iPhone Emoticons Insert into MySQL But Become Blank Value

iPhone emoticons insert into MySQL but become blank value

Most iOS emojis use code points above the Basic Multilingual Plane of the Unicode table. For example, (SMILING FACE WITH OPEN MOUTH AND SMILING EYES) is at U+1F604.

OS X character viewer

Now, see http://dev.mysql.com/doc/refman/5.5/en/charset-unicode.html.

MySQL before version 5.5 only supports UTF-8 for the BMP, which includes characters between U+0000 and U+FFFF (i.e. only a subset of actual UTF-8; MySQL's utf8 is not real UTF-8). It cannot store the character at code point U+1F604 or other similar "high characters". MySQL 5.5+ supports utf8mb4 (actual UTF-8), utf16 and utf32, which are able to encode these characters. If you're using MySQL 5.5+, use one of these column character sets and make sure you're using the same charset for your connection encoding to/from PHP. If you are on MySQL < 5.5, you'll have to use a BLOB column type. That type stores raw bytes without caring about the "characters" in it. The downside is that you won't be able to efficiently search or index the text.

Sending emoticons from iPhone to CakePHP but received blank value

I think what you are trying to do is send the 'image' file and have php capture that data. In order to do that you need to 'capture' the image data with something like:

$img_data = file_get_contents('php://input');

This is PHP specific if you plan on using PHP regardless of the framework. You can read more about how to capture this data here:

http://php.net/manual/en/wrappers.php.php

UPDATE

You need to store it as a blob so it will store the image data correctly.

Emoji character (😀) is not working with utf8mb4_bin in MySQL version 5.6

The connection needs to specify utf8mb4 to MySQL. What is under the covers in DOMDocument?

/code> is hex F09F9880, which should work in a column of CHARACTER SET utf8mb4 with any utf8mb4_* collation.

And here is another link: Trouble with UTF-8 characters; what I see is not what I stored

If all else fails, execute SET NAMES utf8mb4 from PHP after establishing a connection.

Cannot store emoji in database

Okay I finally managed to make it working!
Thanks to everybody that tried to help me, especially @Rick James and @Gerard Roche.

SUGGESTION:

If you need to work with emoji first of all make simple tests on localhost. Create a new database and make a fresh app for testing purpose.

If you follow the steps I wrote in the question or if you follow this tutorial: https://mathiasbynens.be/notes/mysql-utf8mb4#utf8-to-utf8mb4 it must work.

Working locally on a fresh basic app you will have more control and more room to make all the test you need.

SOLUTION:

In my case the problem was in the configuration of the database in CodeIgniter. It was not properly setting up the char_set and the collation for a stupid overlooking: I was overriding the database settings in the function that save messages to be sure it was working with the mobile database.

BEFORE:

function message_save ( $data = FALSE )
{
$project_db_config = array();
$project_db_config['hostname'] = 'MY_HOST';
$project_db_config['username'] = 'MY_USERNAME';
$project_db_config['password'] = 'MY_PASSWORD';
$project_db_config['database'] = 'MY_DATABASE';

$mobile_db = $this->load->database( $project_db_config, TRUE );

// other code to save message
}

AFTER:

function message_save ( $data = FALSE )
{
$mobile_db_connection = $this->load->database('admin_mobile_mh', TRUE);

// other code to save message
}

CONCLUSION:

The app must set the connection to the database properly.
If you have the database properly setup but you don't make the proper connection with your app, it won't work.

So if you encounter similar problems make sure the api properly setup the char_set as utf8mb4 and db_collat as utf8mb4_unicode_ci.



Related Topics



Leave a reply



Submit