Welcome Guest, Not a member yet? Register   Sign In
Emojis
#1

(This post was last modified: 01-24-2023, 09:03 AM by gregknight.)

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

            }

            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.



[Image: 67b73d_k8u]
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?
Reply
#2

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 )
Reply
#3

(01-24-2023, 01:52 AM)InsiteFX Wrote: 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.

This made no difference on what appeared in the database.  Sad
Reply
#4

MySQL table has its charset. If it is not utf8mb4, you cannot save emojis correctly.
Reply
#5

(01-24-2023, 05:14 PM)kenjis Wrote: MySQL table has its charset. If it is not utf8mb4, you cannot save emojis correctly.
I only see a collation for the table and it is set to utf8mb4_unicode_ci.
Reply
#6

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???
Reply
#7

You also need to set it in the app/Config/Database.php file.
PHP Code:
  /**
    * The default database connection.
    */
    public array $default = [
        'DSN'      => '',
        'hostname' => 'localhost',
        'username' => '',
        'password' => '',
        'database' => '',
        'DBDriver' => 'MySQLi',
        'DBPrefix' => '',
        'pConnect' => false,
        'DBDebug'  => true,
        'charset'  => 'utf8mb4',
        'DBCollat' => 'utf8mb4_unicode_ci',
        'swapPre'  => '',
        'encrypt'  => false,
        'compress' => false,
        'strictOn' => false,
        'failover' => [],
        'port'    => 3306,
    ]; 
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB