我正在使用以下数据库配置
'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()
但似乎我没带运气。我在utf8_decode()
上尝试了$URL
,这基本上是通过了这些字母。
任何帮助都会非常感激。
答案 0 :(得分:1)
所以答案基本上是使用utf8_bin
整理,但我已经在生产网站上安装了数据库,这是一个很大的问题。从@BenRoob找到的sql解决方案只在SQL中工作,但Laravel很头疼。
所以,SQL解决方案就是这个
mysql> select word_tr from yeoman_wordbank_ where LCASE(word_tr) like "ğ%" COLLATE utf8_bin;
laravel one就是这个
$query = DB::select( DB::raw( "select * from yeoman_wordbank_ where LOWER($WordDB_Field) like '$URL%' collate utf8_bin" ) );
上面的laravel查询是唯一有效的,我尝试了很多组合。
答案 1 :(得分:0)
您检查了表格整理吗?