Case Sensitive Database Query [duplicate]

半腔热情 提交于 2020-01-02 19:29:08

问题


Possible Duplicate:
mysql case sensitive query

'm working on an PHP script that checks some values to the ones in the database. So far I thought it worked right, but I found an problem.

The query isn't looking for the specific characters.

So if I use this query:

SELECT *
FROM `facilitydb_login`
WHERE
facilitydb_login.`password` = 'PASS'

I want the result, because the password is PASS. But if you fill in pass (lowercase) the same entry is returned.

How can I make it case sensitive?


回答1:


you should use case sensitive collation, for example

SELECT *
FROM `facilitydb_login`
WHERE facilitydb_login.`password` collate latin1_general_cs = 'PASS'

CS in the name means that it's Case Sensitive




回答2:


you could make the column case sensitive

Assume you are using mysql database

ALTER TABLE facilitydb_login 
CHANGE password `password` VARCHAR(100) BINARY NOT NULL;

or If you want to make part of the select statement then

SELECT *
FROM `facilitydb_login`
WHERE BINARY 
facilitydb_login.`password` = 'PASS'


来源:https://stackoverflow.com/questions/12973682/case-sensitive-database-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!