Emojis |
I have an old PHP app that has an email feature. The problem we are having is the Subject and Message boxes in the email feature will not handle saving emojis to the database or retrieving emojis from the database. I currently am just setting the subject column in the database to 5 emojis and the word "test" for testing purposes, so I know what I'm working with. Here is the code doing the insert into the table. I have set the char_set and dbcollat in the database.php file, but it didn't work, so I've also tried setting it here in the code right before the insert. It doesn't work either.
//echo("<script>console.log('PHP MailboxModel saveMessage " . $data['message'] . "');</script>"); $db['default']['char_set'] = "utf8mb4"; $db['default']['dbcollat'] = "utf8mb4_unicode_ci"; $query = $this->ci->db->query("SET character_set_connection=utf8mb4"); $query = $this->ci->db->query("SET character_set_results=utf8mb4"); $data['subject'] = '❤️???❤️test'; if (is_null($message_id)) { if (!isset($data['date_add'])) { $data['date_add'] = date('Y-m-d H:i ![]() } if (!isset($data['is_new'])) { $data['is_new'] = 1; } $this->ci->db->insert(MAILBOX_TABLE, $data); $message_id = $this->ci->db->insert_id(); } else { $this->ci->db->where('id', $message_id); $this->ci->db->update(MAILBOX_TABLE, $data); } $this->updateFulltextField($message_id); return $message_id; } Here are the rows that were saved to the database. Notice that the Subject column has ?? instead of the emojis in the middle. Subject ❤️????????????❤️test I believe the code is using CodeIgniter version 1.7.0. // CI Version define('CI_VERSION', '1.7.0'); Does CI version 1.7.0 even support the inserting and retrieving of emojis into and from the database?
You can get the CI version using echo CI_VERSION;
You may need to use php htmlspecialchars() and php htmlentities() to convert them, run them on the full strings. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
MySQL table has its charset. If it is not utf8mb4, you cannot save emojis correctly.
I've tried everything I know of and it just doesn't work. I'm guessing that CI 1.7.0 didn't support emojis..... So, how hard is it to upgrade very old code to the newer version of CI???
You also need to set it in the app/Config/Database.php file.
PHP Code: /** What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(01-26-2023, 01:07 AM)InsiteFX Wrote: You also need to set it in the app/Config/Database.php file. I have it set in the database.php. I've done everything and it still doesn't work. I don't think emojis were supported in 1.7.0.....
I found this according to this you need to use a BLOB character type for the column.
How to store Emoji Character in MySQL Database Should help you. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |