title: Cannot store emoji in database
body: <p><strong>THE SITUATION</strong>:</p>
  
  <p>Sorry in advance if this question has already been asked, but the solutions aren't working for me.</p>
  
  <p>No matter what I try, I cannot store emoji in my database. They are saved as <code>????</code>. <br />
  The only emojis that are properly saved are the ones that require only 3 bytes, like the shy face or the sun. </p>
  
  <p>The actual utf8mb4 is not working.</p>
  
  <p><a href="https://i.stack.imgur.com/dgvST.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dgvST.png" alt="Database screenshot"></a></p>
  
  <p>It has been tested on both Android and Ios. With same results.</p>
  
  <p><strong>VERSIONS</strong>:</p>
  
  <p>Mysql: 5.5.49 <br />
  CodeIgniter: 3.0.0</p>
  
  <p><strong>THE STEPS</strong>:</p>
  
  <ol>
  <li><p>I have modified database character set and collation properties.</p>
  
  <p><code>ALTER DATABASE my_database CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci</code></p></li>
  <li><p>I have modified table character set and collation properties.</p>
  
  <p><code>ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci</code></p></li>
  <li><p>I have set each field of the table, where possible, as Encoding: <code>UTF-8(ut8mb4)</code> and Collation: <code>utf8mb4_unicode_ci</code></p></li>
  <li><p>I have modified the database connection in the CodeIgniter app.</p></li>
  <li><p>I have run the following: <code>SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci</code></p></li>
  <li><p>Lastly I have also tried this: 
  <code>REPAIR TABLE table_name;
  OPTIMIZE TABLE table_name;</code></p></li>
  </ol>
  
  <p>Everything should have been setup properly but yet it doesn't work.</p>
  
  <p><strong>DATABASE SETTINGS</strong>:</p>
  
  <p>This is the outcome running the following command: </p>
  
  <pre><code>`SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';`
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/8vbJ3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8vbJ3.png" alt="Database settings"></a></p>
  
  <p><strong>TABLE SETTINGS</strong>:</p>
  
  <p>A screeshot of the table structure:</p>
  
  <p><a href="https://i.stack.imgur.com/UhVKt.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UhVKt.png" alt="Table settings"></a></p>
  
  <p><strong>DATABASE CONNECTION</strong>:</p>
  
  <p>These are the database connection settings inside database.php (note this is not the only database, there are also others that connect using utf8)</p>
  
  <pre><code>$db['my_database'] = array(
          'dsn'           =&gt; '',
          'hostname'      =&gt; PROJECT_DATABASE_HOSTNAME,
          'username'      =&gt; PROJECT_DATABASE_USERNAME,
          'password'      =&gt; PROJECT_DATABASE_PASSWORD,
          'database'      =&gt; PROJECT_DATABASE_NAME,
          'dbdriver'      =&gt; 'mysqli',
          'dbprefix'      =&gt; '',
          'pconnect'      =&gt; FALSE,
          'db_debug'      =&gt; TRUE,
          'cache_on'      =&gt; FALSE,
          'cachedir'      =&gt; '',
          'char_set'      =&gt; 'utf8mb4',
          'dbcollat'      =&gt; 'utf8mb4_unicode_ci',
          'swap_pre'      =&gt; '',
          'encrypt'       =&gt; FALSE,
          'compress'      =&gt; FALSE,
          'stricton'      =&gt; FALSE,
          'failover'      =&gt; array(),
          'save_queries'  =&gt; TRUE
      );
  </code></pre>
  
  <p><strong>MY.CNF SETTINGS</strong>:</p>
  
  <p>This is the whole content of the file my.cnf:</p>
  
  <pre><code>[mysqld]
  default-storage-engine=MyISAM
  innodb_file_per_table=1
  max_allowed_packet=268435456
  open_files_limit=10000
  character-set-client-handshake = FALSE
  character-set-server = utf8mb4
  collation-server = utf8mb4_unicode_ci
  
  [client]
  default-character-set = utf8mb4
  
  [mysql]
  default-character-set = utf8mb4
  </code></pre>
  
  <p><strong>THE QUESTION</strong>:</p>
  
  <p>Do you know why is not working? Am I missing something?</p>
  
  <p><strong>HYPHOTESIS 1</strong>:</p>
  
  <p>I am not sure, but the cause of the problem may be this:</p>
  
  <p>As you can see in my.cnf <code>character-set-server</code> is clearly set as <code>utf8mb4</code>:</p>
  
  <p>But after running the query in the database:</p>
  
  <p><code>SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';</code></p>
  
  <p>The outcome is that <code>character-set-server = latin1</code></p>
  
  <p>Do you know why is that? Why is not actually updating?</p>
  
  <p><strong>HYPHOTESIS 2</strong>:</p>
  
  <p>The application use several different databases.
  This one is set to utf8mb4 but all the others are set to utf8. It may be a problem even if they are separated databases?</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>This is the outcome of <code>SHOW CREATE TABLE app_messages;</code></p>
  
  <pre><code>CREATE TABLE `app_messages` (
    `message_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `project_id` bigint(20) NOT NULL,
    `sender_id` bigint(20) NOT NULL,
    `receiver_id` bigint(20) NOT NULL,
    `message` text COLLATE utf8mb4_unicode_ci,
    `timestamp` bigint(20) DEFAULT NULL,
    `is_read` enum('x','') COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    PRIMARY KEY (`message_id`)
  ) ENGINE=InnoDB AUTO_INCREMENT=496 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
  </code></pre>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I have run the following command:</p>
  
  <pre><code>INSERT INTO app_messages (message_id, project_id, sender_id, receiver_id, message, timestamp, is_read)
  VALUES ('496','322','77','188', '' ,'1473413606','x');
  </code></pre>
  
  <p>And other two similar with  and </p>
  
  <p>They were inserted in the table without problems:</p>
  
  <p><a href="https://i.stack.imgur.com/UizxH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/UizxH.png" alt="enter image description here"></a></p>
  
  <p>But in the actual app what i really see is: <code>?</code> (this time only one ? and not 4)</p>