gpt4 book ai didi

php - DB查询土耳其语字母之间的差异 - Octobercms

转载 作者:行者123 更新时间:2023-11-29 10:43:22 27 4
gpt4 key购买 nike

我正在使用以下数据库配置

'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'database' => 'databsename',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],

如您所见,我正在使用 'collat​​ion' => '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;

laravel 是这个

$query = DB::select( DB::raw( "select * from yeoman_wordbank_ where LOWER($WordDB_Field) like '$URL%' collate utf8_bin" ) );

上面的 laravel 查询是唯一有效的,我尝试了很多组合。

关于php - DB查询土耳其语字母之间的差异 - Octobercms,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45059986/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com