Laravel 5 Eloquent 字符集 utf8 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32700518/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 5 Eloquent charset utf8 issues
提问by EkinOf
I use Laravel 5.1 and a mysql server. I have a database with table in utf8 unicode, and my databse configuration file is like this :
我使用 Laravel 5.1 和一个 mysql 服务器。我有一个 utf8 unicode 表的数据库,我的数据库配置文件是这样的:
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'false',
),
But when I use queries from eloquent, my texts which have accents are broken. It's not a problem from blade because I can write accent in the views correctly, and if I use PDO directly my text is nice.
但是当我使用 eloquent 的查询时,我的带有口音的文本被破坏了。这不是刀片的问题,因为我可以正确地在视图中写重音,如果我直接使用 PDO,我的文字很好。
How can I solve my problem with my queries from eloquent ?
我如何通过 eloquent 的查询解决我的问题?
采纳答案by EkinOf
I found my problem, I hope it will help others :
我发现了我的问题,我希望它会帮助其他人:
My Mysql databases are encoded in latin1 by default. I was sure that my databases were in utf8 so I configured as that in the configuration file on my laravel project.
默认情况下,Mysql 数据库以 latin1 编码。我确定我的数据库在 utf8 中,所以我在我的 laravel 项目的配置文件中进行了配置。