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!
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.
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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community