ThingEngineer / PHP-MySQLi-Database-Class

Wrapper for a PHP MySQL class, which utilizes MySQLi and prepared statements.
Other
3.29k stars 1.35k forks source link

Emojis did not save properly #957

Open buttakbar opened 3 years ago

buttakbar commented 3 years ago

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 commented 3 years ago

Will you please update me about it?

igorek24 commented 3 years ago

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

buttakbar commented 3 years ago

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?

igorek24 commented 3 years ago

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.

buttakbar commented 3 years ago

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

WRedMedia commented 2 years ago

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'));

EHBradford commented 2 years ago

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 commented 2 years ago

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

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

EHBradford commented 2 years ago

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.