比如:
$condition = "a_size";$single_size = 30;$sql_count = "select count(*) as count from foot_info WHERE '$condition' = '$single_size' ";
我這樣運行,貌似什麼也查詢不到
但很奇怪,如果我用字串串連成sql語句就可以正常查詢,如下
$sql_count = "select count(*) as count from foot_info WHERE".$condition." = '$single_size' ";
/////////////////////////////////////
我又輸出了上面兩個sql語句的輸出,分別是
select count(*) as count from foot_info WHERE Foot_Size = '30'//可運行select count(*) as count from foot_info WHERE 'Foot_Size' = '30'//不可運行
回複內容:
比如:
$condition = "a_size";$single_size = 30;$sql_count = "select count(*) as count from foot_info WHERE '$condition' = '$single_size' ";
我這樣運行,貌似什麼也查詢不到
但很奇怪,如果我用字串串連成sql語句就可以正常查詢,如下
$sql_count = "select count(*) as count from foot_info WHERE".$condition." = '$single_size' ";
/////////////////////////////////////
我又輸出了上面兩個sql語句的輸出,分別是
select count(*) as count from foot_info WHERE Foot_Size = '30'//可運行select count(*) as count from foot_info WHERE 'Foot_Size' = '30'//不可運行
把$condition的引號去掉就好。。
mysql的查詢欄位不需要加引號或者select count(*) as count from foot_info WHERE `Foot_Size` = '30'//可運行
select * from foot_info WHERE 1=1;select * from foot_info WHERE 1=0;
在postgresql中表名和欄位名是單引號;在Mysql中表名和欄位名必須``或不寫一句話概括就是Mysql的單引號和雙引號會被Mysql當成字串處理,`符號內是表名或者欄位處理