Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I store unicode emoji to MYSQL in CodeIgniter

I'm using codeigniter and trying to save 🚚 to a MYSQL database table

The error i'm getting is

Incorrect string value: '\xF0\x9F\x9A\x9A' for column 'post'
like image 752
PK. Avatar asked Dec 19 '13 12:12

PK.


People also ask

Can you save emojis in mysql?

Some emojis such as âš¡ can be stored in MySQL's 3-byte utf8 encoding, but others such as face screaming in fear cannot.

How do I save emojis in phpmyadmin?

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.

Can emojis be represented by Unicode?

The Unicode Standard has assigned numbers to represent emojis. Here's how it works. In the Unicode Standard, each emoji is represented as a "code point" (a hexadecimal number) that looks like U+1F063, for example.


1 Answers

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';
like image 153
PK. Avatar answered Sep 24 '22 21:09

PK.