Mysql string 0

why select 'aaa' =0 return 1 (TRUE) if I have a table like

 userid | pass user1 | pas1 

if I ask:

 select from table where userid = 0 and pass =0 

Does he give me all the lines?

+6
source share
1 answer

MySQL sees 'aaa' = 0 and thinks about itself:

"I can either convert aaa to an integer, or 0 to a string."

Guess who he's walking with?

Basically, what happens is that "aaa" is converted to an integer, and since it is not a real integer, it distinguishes 0.

0 = 0, of course, true (or true == 1).

I suspect the same thing is happening with your userid column, although without knowing its values ​​/ data type, it's hard to say.

http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html

+10
source

Source: https://habr.com/ru/post/912072/


All Articles