Can not store emojis in MySQL table
I have a “comments” table in my MySQL database which I want to store peoples’ comments in it . the comments may contain emojis . the problem is that the emoji values is stored as 0 . for example is stored as 0.
my database default collation is utf8mb4
comments table has the collation of utf8mb4_bin
also comment column has VARCHAR
type and utf8mb4_bin
collation.
when I try to store the emoji directly I get this error :
Operation failed: There was an error while applying the SQL script to the database.
Executing:
UPDATE `db`.`comments` SET `comment`='π' WHERE `id`='1';
ERROR 1366: 1366: Incorrect string value: 'xF0x9Fx98x83' for column 'comment' at row 1
SQL Statement:
UPDATE `db`.`comments` SET `comment`='π' WHERE `id`='1'
Also my Laravel migration code is this :
Schema::create('comments', function (Blueprint $table) {
$table->increments('id');
$table->string('page_id');
$table->string('media_id');
$table->string('short_code');
$table->string('owner_id');
$table->string('media_name');
$table->text('display_url');
$table->boolean('is_video');
$table->string('video_url')->nullable()->default(null);
$table->boolean('status')->default(0);
$table->integer('ts')->default(0);
$table->text('comment')->collation('utf8mb4_bin');
$table->collation = "utf8mb4_bin";
});
I have tried How to store Emoji Character in My SQL Database but no luck.
from Laravel Questions and Answers https://laravelquestions.com/php/can-not-store-emojis-in-mysql-table/
via Lzo Media
No comments:
Post a Comment