Case Sensitive Database Query [duplicate]

2019-05-27 10:12发布

问题:

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'