MySQL loose comparison on INT fields
I recently saw something in MySQL which I consider odd, however, I am
unsure if it is MySQL doing this or PHP.
Basically I have this query using the PDO library:
SELECT * FROM users WHERE id=:id OR email=:id
Using the bound parameter of xxx@gmail.com as :id. It is able to find the
record where email is NULL and id is 0. After some investigation I found
out that this was because there was some lose casting being done that
meant xxx@gmail.com was being casted as 0 (like in PHP) to compare with
id.
Is this MySQL or PHP? Is there a way to stop loose casting and comparisons
from happening in MySQL using the PHP PDO driver?
If it matters my table is MyISAM.
No comments:
Post a Comment