why select 'aaa' =0 return 1 (TRUE)
if i have a table like
userid | pass
user1 | pas1
if I query :
select from table where userid = 0 and pass =0
it gives me all the rows?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
MySQL sees ‘aaa’ = 0 and thinks to itself:
“I can either convert aaa to an integer, or 0 to a string.”
Guess which one it goes with?
Basically what’s happening is that ‘aaa’ is being converting to an integer, and as it’s not a valid integer, it casts to 0.
0 = 0 is of course true (or true == 1).
I suspect the same is happening with your userid column, though without knowing its values/datatype, it’s hard to say.
http://dev.mysql.com/doc/refman/5.0/en/type-conversion.html