PHP MYSQL 查询数据库时检查大小写
查询数据库时如何检查字符串的大小写?例如,使用以下语句:
mysql_query("SELECT id FROM members WHERE username = '$username'");
数据库中的值为“Test”。然而,用户可以输入“test”,它仍然可以工作。如何查看具体情况?我尝试过 === 和 ==,但显然它们在 SQL 中不起作用。
How do I check the case of a string when querying the database? For example, with this statement:
mysql_query("SELECT id FROM members WHERE username = '$username'");
The value in the database is "Test". The user could, however, type in "test" and it would still work. How do I check the exact case? I've tried === and ==, but apparently they don't work in SQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的排序规则需要区分大小写。
将用户名列的排序规则更改为区分大小写的排序规则。
例如,如果您仅在用户名列中使用拉丁字符,请将其更改为
latin1_general_cs
或latin7_general_cs
或
Your collation needs to be case sensitive.
Change the collation of the username column to a case sensitive one.
For example if you are using latin characters only in the username column, then change it to
latin1_general_cs
orlatin7_general_cs
or
您使用什么 SQL 服务器?鉴于您使用的是 PHP,我将假设它是 mysql 并向您发送 此处。
What SQL server are you using? Given that you're using PHP, I'm going to assume it's mysql and send you here.
使用 == 运算符检查数据库的值,例如:
Use the == operator to check the value of the database for example: