Description:
First. the SQL "SELECT * FROM gl_user WHERE username=0;" is not good
Second. convert username's value from character to int,but not display any
warning information
finally: the SQL return data is not right
root@localhost : test 11:27:41> SELECT * FROM gl_user WHERE username=0;
+-----+-------------+
| id | username |
+-----+-------------+
| 303 | @testregext |
| 304 | test!regext |
| 305 | testregext |
| 306 | sdfsd |
| 307 | sdfsd |
+-----+-------------+
5 rows in set (0.00 sec)
MySQL provide function(convert & cast ) don't allow convert un-interge data to interge,if you execute "SELECT CONVERT('sd' ,INT)" ,it has grammar's error information.
so i think SQL don't convert column's values to parameter's data type ,should convert paratemer's value to columns's data type.
Example:
root@localhost : test 04:40:16> show columns from gl_user;
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| username | varchar(40) | YES | | NULL | |
+----------+-------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
SELECT * FROM gl_user WHERE username=0;
auto convert 0 to varchar(Example:'0')
How to repeat:
root@localhost : test 11:18:03> INSERT INTO gl_user(username) VALUES('@testregext'),('test!regext'),('testregext'),('sdfsd'),('sdfsd'),(NULL);
Query OK, 6 rows affected (0.00 sec)
Records: 6 Duplicates: 0 Warnings: 0
root@localhost : test 11:20:50> SHOW CREATE TABLE gl_user;
+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| gl_user | CREATE TABLE `gl_user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(40) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=303 DEFAULT CHARSET=utf8 COLLATE=utf8_bin |
+---------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
root@localhost : test 11:21:23> SELECT * FROM gl_user;
+-----+-------------+
| id | username |
+-----+-------------+
| 303 | @testregext |
| 304 | test!regext |
| 305 | testregext |
| 306 | sdfsd |
| 307 | sdfsd |
| 308 | NULL |
+-----+-------------+
6 rows in set (0.00 sec)
root@localhost : test 11:21:40> SELECT * FROM gl_user WHERE username=0;
+-----+-------------+
| id | username |
+-----+-------------+
| 303 | @testregext |
| 304 | test!regext |
| 305 | testregext |
| 306 | sdfsd |
| 307 | sdfsd |
+-----+-------------+
5 rows in set (0.00 sec)
root@localhost : test 11:27:32> INSERT INTO gl_user VALUES(309,1);
Query OK, 1 row affected (0.00 sec)
root@localhost : test 11:27:36> SELECT * FROM gl_user;
+-----+-------------+
| id | username |
+-----+-------------+
| 303 | @testregext |
| 304 | test!regext |
| 305 | testregext |
| 306 | sdfsd |
| 307 | sdfsd |
| 308 | NULL |
| 309 | 1 |
+-----+-------------+
7 rows in set (0.00 sec)
root@localhost : test 11:27:41> SELECT * FROM gl_user WHERE username=0;
+-----+-------------+
| id | username |
+-----+-------------+
| 303 | @testregext |
| 304 | test!regext |
| 305 | testregext |
| 306 | sdfsd |
| 307 | sdfsd |
+-----+-------------+
5 rows in set (0.00 sec)
root@localhost : test 11:28:10> SELECT * FROM gl_user where username='0';
Empty set (0.00 sec)