Reputation:
I am using Emoji character in my project for facebook post. Some emoji character are saved good but some characters are saved like (??) into mysql database. My database table Default collation is utf8mb4_unicode_ci . Is there any way to save all emoji into database.
I am working in Cakephp3. My database structure is :
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => '******',
'password' => '******',
'database' => '******',
'encoding' => 'utf8mb4',
'timezone' => 'UTC',
'flags' => [],
'cacheMetadata' => true,
'log' => false,
'url' => env('DATABASE_URL', null),
],
Upvotes: 0
Views: 1004
Reputation: 3280
I had a similar problem to this when dealing with unusual characters such as this. The issue wasnt with the database, it was with how i was connecting to the database. Since you have provided no code, I can't give any specific advice, but check your DB connection string and make sure its using the mb4 version of utf8. Otherwise the response will not contain the characters.
If you are using PDO, then your db string will look like this.
$db = 'mysql:host=example.com;dbname=testdb;port=1234;charset=utf8mb4';
Upvotes: 3