【发布时间】:2017-07-12 14:06:31
【问题描述】:
我正在为数据库使用以下配置
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'database' => 'databsename',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
如您所见,我使用的是'collation' => 'utf8_unicode_ci' 和'charset' => 'utf8'。我遇到的问题是查询土耳其字符。例如,它对 English G 和 Turkish Ğ 的处理与其他土耳其字符相同。
查看这个 mysql 示例
mysql> select * from yeoman_wordbank_ where word_tr like "ğ%";
+----+-----------+--------------------------+------------+---------------------+---------------------+---------------------+--------------+----------------+----------------+----------------+
| id | word_tr | word_gr | pubordraft | created_at | updated_at | deleted_at | word_image | description_en | description_tr | description_gr |
+----+-----------+--------------------------+------------+---------------------+---------------------+---------------------+--------------+----------------+----------------+----------------+
| 22 | gurbet | γρουμπέτι | 0 | 2017-06-08 06:25:19 | 2017-06-23 11:39:40 | 2017-06-23 11:39:40 | /image19.jpg | | | |
| 23 | gurbetçe | γκρουμπέτικα | 0 | 2017-06-08 06:26:19 | 2017-06-23 11:39:40 | 2017-06-23 11:39:40 | /image20.jpg | | | |
| 32 | Gancelli | Καντζέλλιν | 1 | 2017-07-12 16:31:40 | 2017-07-12 16:31:40 | NULL | | | | |
| 33 | Gabira | Καπύρα | 1 | 2017-07-12 16:32:37 | 2017-07-12 16:32:37 | NULL | | | | |
+----+-----------+--------------------------+------------+---------------------+---------------------+---------------------+--------------+----------------+----------------+----------------+
4 rows in set (0.00 sec)
如您所见,它给了我正常 English G 的结果,而不是 Turkish ğ
PS:我是用这个来查询的
Word::where( $WordDB_Field, 'LIKE', $URL .'%' )->get()
但我似乎没有带来好运。我在$URL 上也试过utf8_decode(),这基本上是在传递字母。
任何帮助将不胜感激。
【问题讨论】:
-
确实是排序规则问题。请看这里:stackoverflow.com/questions/2607130/… 知道,这个问题是指德语变音符号,但也许这是一个有用的提示——尤其是 mysql 文档的链接。
-
确实如此!我在排序规则方面苦苦挣扎,我现在无法更改:/ laravel 也没有在运行时进行查询。虽然解决方法是这个mysql> select * from yeoman_wordbank_ where word_tr like "ğ%" collate utf8_bin;但无法编码。在 DB:raw 中尝试过。它说“SQLSTATE [42000]:语法错误或访问冲突:1253 COLLATION 'utf8_bin' 对 CHARACTER SET 'binary' 无效(SQL: select * from
yeoman_wordbank_where LOWER(word_tr) LIKE ğ% collate utf8_bin)” )。 -
终于解决了,非常感谢分享那个链接!!!
-
哦对了,忘记了,谢谢提醒。
标签: php mysql laravel octobercms