PHP-MySQLi-Database-Class icon indicating copy to clipboard operation
PHP-MySQLi-Database-Class copied to clipboard

Emojis did not save properly

Open buttakbar opened this issue 4 years ago • 9 comments

I was using older version 2.6 and everything was fine, But I have updated to 2.9.3 yesterday and I noticed that emojis did not save and retrieved properly with the updated class.

buttakbar avatar Feb 26 '21 07:02 buttakbar

Will you please update me about it?

buttakbar avatar Mar 02 '21 13:03 buttakbar

Make sure your characterset is utf8mb4 and your collation is utf8mb4_unicode_ci on your DB shcema

igorek24 avatar Mar 13 '21 00:03 igorek24

I had implemented the collation at the column level and It's working fine with the old version. is there any update that required these updated at DB level?

buttakbar avatar Mar 16 '21 10:03 buttakbar

You need to either convert each table individually:

ALTER TABLE mytable CONVERT TO CHARACTER SET utf8mb4

(this will convert the columns just as well), or export the database and import it back with utf8mb4.

I usually change it on the server side as a default.

igorek24 avatar Mar 16 '21 15:03 igorek24

I did all that but still the issue is there. I have updated the Database character set and collation, I have update it for the table and columns as well but still the issue is same, Please review the attached images column_collation DB_character_set table_collation

buttakbar avatar May 05 '21 08:05 buttakbar

I did all that but still the issue is there.

Use utf8mb4 in charset conf $this->db = new MysqliDb (Array( 'host' => $JConfig->host, 'username' => $JConfig->user, 'password' => $JConfig->password, 'db' => $JConfig->db, 'prefix' => $JConfig->dbprefix, 'charset' => 'utf8mb4'));

WRedMedia avatar Jan 17 '22 11:01 WRedMedia

I am also having this issue. I believe my table is correctly defined:

CREATE TABLE `trains` (
  `trn_id` bigint unsigned NOT NULL AUTO_INCREMENT,
  `emoji` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT 'emoji',
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

I believe my charset is correct as well. Since it follows the template of WRedMedia's post.

I can use the standard SQL insert methods without any issue on my table.

EHBradford avatar Feb 02 '22 04:02 EHBradford

More info, the $db->getLastError() call reveals the following:

Incorrect string value: 'xF0x9Fx8DxBB' for column 'emoji' at row 1

EHBradford avatar Feb 02 '22 04:02 EHBradford

I just double-triple-quadruple checked my work and found in this particular instance that my opening of a connection to the database was not specifying the charset correctly nor the collation. It is working properly now. Thank you for your hard work.

EHBradford avatar Feb 02 '22 05:02 EHBradford