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:
mysqli_set_charset($con,"utf8");
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 DOMDocument
?
/code> is hex
F09F9880
, which should work in a column of CHARACTER SET utf8mb4
with any utf8mb4_*
collation.
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';
Related Topics
How to Count Number of Digits After a Decimal Place
Mysql: Alter Table If Column Not Exists
Select Different Values from Same Column in a Table and Display It Under Different Columns
How to Add Leading Zero When Number Is Less Than 10
How to Combine First Name, Middle Name and Last Name in SQL Server
How to Modify Query to Remove Double-Quotes from All Columns
Insert Multiple Rows Without Repeating the "Insert into ..." Part of the Statement
Using Where Clause With Two Type of Conditions on Same Column
How to Select the Last Record of a Table in SQL
Select All Dates Between First Day of Month and Current Date
How to Pass Multiple Values to Single Parameter in Stored Procedure
How to Create Column in SQL Query With Custom Text
Phone Number Display Method, SQL Query
How to Convert from Blob to Text in MySQL
How to Return a Flag If Exist Id in Another Table MySQL