How to store Emoji Character in MySQL Database
Step 1, change your database's default charset:
ALTER DATABASE database_name CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci;
if the db is not created yet, create it with correct encodings:
CREATE DATABASE database_name DEFAULT CHARSET = utf8mb4 DEFAULT COLLATE = utf8mb4_unicode_ci;
Step 2, set charset when creating table:
CREATE TABLE IF NOT EXISTS table_name (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;
or alter table
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
ALTER TABLE table_name MODIFY field_name TEXT CHARSET utf8mb4;
Storing emojis in MySql database. Showing ??? in phpmyadmin
I finally got the solution.
We will have to set our connection charset to utf8.
After declaring connection variable set charset:
After that your emoji or any other unicode text will be encrypted and saved in mysql database.
Emoji character (😀) is not working with utf8mb4_bin in MySQL version 5.6
The connection needs to specify
utf8mb4 to MySQL. What is under the covers in
/code> is hex
F09F9880, which should work in a column of
CHARACTER SET utf8mb4 with any
And here is another link: Trouble with UTF-8 characters; what I see is not what I stored
If all else fails, execute
SET NAMES utf8mb4 from PHP after establishing a connection.
How do I store unicode emoji to MYSQL in CodeIgniter
1) Ensure you're using MYSQL 5.5 only then will you be able to change the collation to utf8mb4_something
2) Ensure table columns that are going to receive emoji have their collation set to utf8mb4_something
3) Edit your database.php config file
$db['default']['char_set'] = 'utf8mb4';
$db['default']['dbcollat'] = 'utf8mb4_unicode_ci';