简体   繁体   English

MySQL SELECT查询不区分大小写吗?

[英]Are MySQL SELECT queries case-insensitive?

I have a form with method post, users will filter results by brand date etc. If the brand name in the MySQL is stored with non lowercase example ( samsung ) and the search input field is filled with uppercase example ( SAMSUNG ) will it still give me the correct results or will cause errors ? 我有一个带有方法post的表单,用户将按品牌日期等过滤结果。如果MySQL中的品牌名称以非小写示例(samsung)存储,并且搜索输入字段充满大写示例(SAMSUNG),它将仍然给出我的结果正确还是会导致错误?

$branded=mysqli_real_escape_string($db, $_GET['brand']); // USER TYPED SAMSUNG
}
$query= "SELECT * FROM `brands` WHERE `brand` = '$branded' LIMIT 1"; // stored as samsung

The locale is "latin1_swedish_ci". 语言环境为“ latin1_swedish_ci”。

Because it ends in "ci", it must be c ase- i nsensitive. 因为它在“CI”结尾,则它必须使用C ASE- nsensitive。

Most MySQL collations are case-insensitive, unless you are doing a binary comparison. 除非您进行二进制比较,否则大多数MySQL排序规则都不区分大小写。 In your query case shouldn't change anything. 在您的查询情况下,不应更改任何内容。 However the following query would mark "samsung" and "SAMSUNG" as different: 但是,以下查询会将“ samsung”和“ SAMSUNG”标记为不同:

$branded=mysqli_real_escape_string($db, $_GET['brand']); // USER TYPED SAMSUNG
}
$query= "SELECT * FROM `brands` WHERE BINARY `brand` = '$branded' LIMIT 1"; // stored as samsung

You would have to check your collation to know for sure whether it is case-sensitive but the easiest way would just be to test it. 您必须检查您的排序规则,以确保它是否区分大小写,但是最简单的方法就是对其进行测试。

Use this link as a reference: 使用此链接作为参考:

http://dev.mysql.com/doc/refman/5.0/en/charset-binary-op.html http://dev.mysql.com/doc/refman/5.0/en/charset-binary-op.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM