0

Hello,

I have a table with a filed Customers defined as int(10)
I have the following query:
SELECT * FROM 'table' where Customers = 'a'
This query returns all entries which have 0 in this field, BUT a is not equal to 0 as we know?

Also I can use any string, not only 'a'.

BUT on other database the same query works as expected. It doesn't return any entries.

Any explanation ?

3
Contributors
2
Replies
17
Views
1 Year
Discussion Span
Last Post by diafol
0

Why are you searching a field you know to be of type INT with a string?

You should validate all data prior to using the query. Even your query string has the single quotes, suggesting a string. Doesn't make sense.

You have posted in PHP, so I assume that you're using mysqli or PDO (if not, you should be). You'd most likely be using a prepared statement, binding the typed value (INT).

AFAIK, if MySQL can't parse strings destined for INT fields (i.e. not a string integer, like '9'), it will treat it as 0 (zero).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.