Preface: The so-called pit, two meaning, one is the software itself bug, one is the user often make mistakes.
Phper often deals with MySQL in daily development. Especially in small and medium-sized applications without layering, phper development should focus on the implementation of SQL statements.
To the point, the table statement is built:
DROP TABLE IF EXISTS ' test_sql ';
CREATE TABLE ' Test_sql ' (
' id ' int (ten) unsigned not NULL auto_increment COMMENT ' self-increment id ',
' Name ' varchar (+) not NULL DEFAULT ' 0 ' COMMENT ' name ',
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=1 DEFAULT charset=utf8 comment= ' Test form ';
Data on:
INSERT into ' test_sql '
VALUES
(' 1 ', ' 0 '),
(' 2 ', ' www.haodaquan.com '),
(' 3 ', ' 0 '),
(' 4 ', ' 123 '),
(' 5 ', ' 123php '),
(' 6 ', ' 123php on the Road '),
(' 7 ', ' PHP on the Road ');
Okay, here's the Watch:
Here's the question: Look for data with a name value of 0.
So the wrong SQL came out:
Select ' id ', ' name ' from Test_sql where name=0
The results are inconsistent with expectations, such as:
Why?
SQL is also a weak type, but it also returns true when comparing 0 and string.
The correct sql:
Select ' id ', ' name ' from Test_sql where name= ' 0 '
Conclusion: The field of a character type must be quoted when you make a where condition.
MySQL those things (6) where conditional string quotes