如何区分SELECT查询中的大写或小写单词

如何区分SELECT查询中的大写或小写单词

问题描述:

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

基本上我觉得问题很简单。 但无法找到任何解决方法。 p>

在登录表单中,我使用php查询我的数据库,通过从数据库表中选择任何行来检查传递的用户名和密码 有这两个值。 p>

当我登录ex时,似乎是什么问题。 p>

user:mm p>

传递:oo p> blockquote>

这样可行。 这是正确的,因为它们在db表上。 p>

但现在如果我使用 p>

user:MM p >

传递:oo p> blockquote>

仍然有效? 哪个不应该。 因为我的数据库只有用户'mm'而不是'MM'。 我需要它来区分上部和下部 因为在其他行中我混合了上部和下部字母 p> div>

You'll have to change the collation/encoding of the column from a "case-insensitive" encoding to a case-sensitive one, such as utf8_general_cs or latin1_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.