[英]DB query difference between Turkish Letters - Octobercms
我正在對數據庫使用以下配置
'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'
。 我遇到的問題是查詢土耳其語字符。 例如,將英語G和土耳其語 Ğ對待也與其他土耳其語字符相同。
看到這個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)
如您所見,它給了我普通英語G的結果,而不是土耳其語ğ
PS:我用這個來查詢
Word::where( $WordDB_Field, 'LIKE', $URL .'%' )->get()
但是似乎我沒有運氣。 我也在$URL
上嘗試了utf8_decode()
,這基本上是通過字母。
任何幫助將非常感激。
所以答案基本上是使用utf8_bin
排序規則,但是我的數據庫已經在生產站點中了,這是一個很大的問題。 從@BenRoob找到的sql解決方案僅在SQL中有效,但Laravel頭疼。
因此,SQL解決方案是這樣的
mysql> select word_tr from yeoman_wordbank_ where LCASE(word_tr) like "ğ%" COLLATE utf8_bin;
幼蟲是這個
$query = DB::select( DB::raw( "select * from yeoman_wordbank_ where LOWER($WordDB_Field) like '$URL%' collate utf8_bin" ) );
上面的laravel查詢是唯一有效的查詢,我嘗試了多種組合。
您檢查表排序了嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.