Why sql = FALSE always returns true

No matter what I do in MySQL 5.0, for example

SELECT 'test' = FALSE

SELECT '' = FALSE

I always get 1 back in SQL. What is the reason for this? I expected 0 or FALSE

EDIT adding context to questions. So the problem arose, it so happened that $ name inadvertently became false, since this connection always passed, then I wondered why this works.

SELECT a.id
FROM user a 
INNER JOIN inventory b ON b.user_id = a.id AND b.name = $name
+5
source share
2 answers

In MySql, FALSE is a constant literal that always evaluates to 0.

So, you are checking to see if 'test' = 0or if '' = 0, and since you are comparing a string with an integer, MySql will try to pass the string to an integer.

If you try this query:

SELECT 'test' = FALSE

1 (TRUE), "test" 0, :

SELECT '1test' = FALSE

0 (FALSE), '1test' 1.

+4

MySQL (.. =)

:

.

, :

  • 'test' 0
  • FALSE 0
  • 0 = 0 TRUE.
+3

All Articles