Support the ongoing development of Laravel.io →
Configuration Database Eloquent

Hi,

I'm trying to save records to my DB that have Chinese characters in them, but they're showing up as ?'s in mysql. I've tried this with both eloquent and fluent, and both have the same issue. I don't think this is a db-level issue because I can insert records with Chinese in them via the mysql cli. Here's the database connection config and table information:

'stuff' => array( 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'stuff', 'username' => 'user', 'password' => 'secret', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', ),

CREATE TABLE stuff ( id int(10) unsigned NOT NULL AUTO_INCREMENT, foo varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, bar varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, baz varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci DEFAULT NULL, count int(11) NOT NULL DEFAULT '0', approved tinyint(1) NOT NULL DEFAULT '0', created_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', updated_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id) ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

Anyone have any ideas?

Thanks!

Last updated 2 years ago.
0

After digging around I found out that this was due to a really silly issue... everything was actually being inserted into the DB correctly, but apparently the MySQL cli doesn't use utf8 by default. Running the cli with the --default-character-set=utf8 flag made everything show up corectly. I hope this saves someone else some time.

Last updated 2 years ago.
0

jacobogreen said:

After digging around I found out that this was due to a really silly issue... everything was actually being inserted into the DB correctly, but apparently the MySQL cli doesn't use utf8 by default. Running the cli with the --default-character-set=utf8 flag made everything show up corectly. I hope this saves someone else some time.

Thanks, your solution is really save hours for me.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.