I have got a Mysql (5.1.58-1ubuntu1) ‘users’ table (InnoDB storage engine, utf8 general ci collation) with 3 fields (for simplicity) :
- id : int (primary key)
- username : varchar(255) – utf8_general_ci
- password : varchar(255) – utf8_general_ci
In this table there are only two records (always for simplicity):
id| username | password
-----------------------
1 | myuser | custom1
2 | myuser2 | custom2
So, if i run this query
select * from users where username = 0 and password = 0
mysql return me all records.
On the contrary , if i run the query below
select * from users where username = '0' and password = '0'
MySql return me an empty set.
For my opinion this behavior is very strange and it seems a Hard Bug.
Someone has any explanations?
It’s not a bug. You can only compare values of the same types, so MySQL silently converts your text ‘myuser’ to an integer with the value of 0.