在 Mysql 查询中使用 COLLATE 时出错 [英] Getting an error when using COLLATE in a Mysql query

查看:44
本文介绍了在 Mysql 查询中使用 COLLATE 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 MySQL 查询中使用 COLLATE 子句,但出现错误.这是我的代码:

I am trying to use the COLLATE clause in a MySQL query and I am getting an error. Here is my code:

<?php    

$sql = "SELECT * FROM users WHERE first_name LIKE '%" . $name ."%' COLLATE uf8_general_ci";

    $members = User::find_by_sql($sql);

?>

如果我去掉 COLLADE 子句,查询就可以正常工作.是不是语法有问题?

If I take out the COLLADE clause the query works properly. Is it something wrong with the syntax?

谢谢!

推荐答案

SELECT * FROM users WHERE first_name LIKE '%" . $name ."%' COLLATE uf8_general_ci

UF8 是什么排序规则?印刷错误很容易被忽视.

What collation is UF8? Typographical errors can be easily overlooked.

必须是:

SELECT * FROM users WHERE first_name LIKE '%" . $name ."%' COLLATE utf8_general_ci

另外,请确保您使用的排序规则与您的字符集兼容.(例如,UTF8 的排序规则与 UTF8MB4 不兼容)

Also, make sure that the collation you are using is compatible with your character set. (e.g. A collation of UTF8 is not compatible with UTF8MB4)

使用此语句检查您的字符集和排序规则(来自 MySQL数据库字符集和整理)

Use this statement to check your charset and collation (from MySQL Database Character Sets and Collation)

SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'db_name';

这篇关于在 Mysql 查询中使用 COLLATE 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆