【问题标题】:DB query difference between Turkish Letters - Octobercms土耳其字母之间的数据库查询差异-Octobercms
【发布时间】: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 GTurkish Ğ 的处理与其他土耳其字符相同。

查看这个 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 "ğ%" collat​​e utf8_bin;但无法编码。在 DB:raw 中尝试过。它说“SQLSTATE [42000]:语法错误或访问冲突:1253 COLLATION 'utf8_bin' 对 CHARACTER SET 'binary' 无效(SQL: select * from yeoman_wordbank_ where LOWER(word_tr) LIKE ğ% collat​​e utf8_bin)” )。
  • 终于解决了,非常感谢分享那个链接!!!
  • 哦对了,忘记了,谢谢提醒。

标签: php mysql laravel octobercms


【解决方案1】:

所以答案基本上是使用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 查询是唯一有效的,我尝试了很多组合。

【讨论】:

    【解决方案2】:

    您是否检查过您的表格排序规则?

    【讨论】:

      猜你喜欢
      • 2013-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      • 2022-07-02
      • 2012-05-13
      • 2016-02-28
      • 2013-10-02
      相关资源
      最近更新 更多