【发布时间】:2019-08-05 18:35:07
【问题描述】:
我想使用 laravel 应用程序将印地语字符存储在 mysql 数据库中
我有以下数据库属性
Database charset = utf8
Database collation = utf8_general_ci
这些设置与 config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'db'),
'username' => env('DB_USERNAME', 'user'),
'password' => env('DB_PASSWORD', 'password'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_general_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
但是当我尝试存储数据时,它给了我这个错误
"message": "SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '=' (SQL: select * from `col` where (`name` = \u091b\u0924\u094d\u0924\u094b\u0917) limit 1)",
"exception": "Illuminate\\Database\\QueryException",
请给我一些建议,我不明白我错过了什么
【问题讨论】:
-
你真的有像
\u091b\u0924\u094d\u0924\u094b\u0917这样的unicode字符串吗?你应该坚持使用 UTF-8 编码。
标签: mysql database laravel utf-8