Mysql WHERE OR WHERE began with integer weird results

why

$query = "SELECT * FROM `users` WHERE `id` = '$search' OR `email` = '$search' LIMIT 1";

`id` = UNSIGNED INTEGER(10), `email` = VARCHAR(255)

why the query results are so strange, I think the image is explained on its own, but I also need a word, so here it is, when the user searches for dcm2@example.com or something else does not exist, no results, but if the line starts with a number and looking for PRIMARY KEY, it turns the string into an integer, if I look for 2dcm1@example.com , return ID 2, any good explanation and why is this happening?

enter image description here

enter image description here

enter image description here

+4
source share
1 answer

, MySql , ( , id ).

:

, , . . , MySQL .

( ):

mysql> SELECT 1 > '6x';
        -> 0
mysql> SELECT 7 > '6x';
        -> 1
mysql> SELECT 0 > 'x6';
        -> 0
mysql> SELECT 0 = 'x6';
        -> 1

, -, , ( , SELECT). , id:

mysql> SELECT CAST(6 AS CHAR) = '6x';
        -> 0
mysql> SELECT CAST(6 AS CHAR) = 6;
        -> 1

, . , , php- ( ).

+4

Source: https://habr.com/ru/post/1681889/


All Articles