Laravel 数据库字符集和排序规则
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42245662/
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 Database charset and collation
提问by Nandakumar
In Laravel, Everytime, while running the website,
在 Laravel 中,每次运行网站时,
"set names 'utf8' collate 'utf8_unicode_ci'"
“设置名称'utf8'整理'utf8_unicode_ci'”
is executing.
正在执行。
How can I avoid this ? Instead of doing this in the code. We have configured in the database itself. How can I remove charset and collation in database configuration ?
我怎样才能避免这种情况?而不是在代码中这样做。我们已经在数据库本身中进行了配置。如何删除数据库配置中的字符集和排序规则?
> config/database.php
>
> 'database' => [
> 'driver' => 'mysql',
> 'host' => env('DB_HOST', 'localhost'),
> 'port' => env('DB_PORT'),
> 'database' => env('DATABASE'),
> 'username' => env('DB_USERNAME', 'forge'),
> 'password' => env('DB_PASSWORD', ''),
> 'charset' => 'utf8', // Need to remove or make ''
> 'collation' => 'utf8_unicode_ci', // Need to remove or make ''
> 'prefix' => env('DB_PREFIX', ''),
> 'strict' => false, ],
回答by Soul's tear Go
You can just remove 'charset' and 'collation' from mysql connection array and run php artisan config:clear after that.
您可以从 mysql 连接数组中删除 'charset' 和 'collation' 并在此之后运行 php artisan config:clear 。
回答by darthsoup
Not directly sure what you try to achieve with this. But it is not possible without changing the MySQL Classes.
不能直接确定您尝试通过此实现什么。但是不改变 MySQL 类是不可能的。
Take a look at the Illuminate/Database/Connectors/MySqlConnector Class.