简体   繁体   中英

How to differ between a upper or lower case words in a SELECT query

Basically i feel like the problem is simple. but cant find any fix for it.

In a login form, i use php to query my database which on its side check the passed username and password by selecting from the database table any row that has that 2 values.

What seems to be the problem is when i login for ex.

user: mm

pass: oo

that works. and that is right as they are on the db table.

but now if i use

user: MM

pass: oo

still works?? which should not. As my db has only user as 'mm' not 'MM'. I need it to distinguish between upper and lower because in other rows i have mix of upper an lower letters

您必须将列的排序/编码从“不区分大小写”的编码更改为区分大小写的编码,例如utf8_general_cslatin1_general_cs

you need to use case sensitive encoding

From 10.1.2. Character Sets and Collations in MySQL

There is a convention for collation names: They start with the name of the character set with which they are associated, they usually include a language name, and they end with _ci (case insensitive), _cs (case sensitive), or _bin (binary).

so use case sensitive like utf8_general_cs or latin1_general_cs

You can update the table using the query:

ALTER TABLE `your_table`  CHARSET=latin1 COLLATE=latin1_general_cs;

Where it says latin1_general_cs , the cs specifies that it is case sensitive. If you ever desire it not to be case sensitive in the future you can just use this query:

ALTER TABLE `your_table`  CHARSET=latin1 COLLATE=latin1_general_ci;

the ci spcifies that it is case insensitive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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