First of all, I am using the DATE_ADD function for MySQL. When trying to use $sqlA
in php, it saids syntax error for some reason (mainly the area after WHE开发者_运维知识库RE). Why?
$sqlA = "SELECT $column_name FROM $table_name WHERE Date >= DATE_ADD(CURDATE(), - INTERVAL 3 DAY)";
However, it works without DATE_ADD:
$sqlB = "SELECT column FROM table WHERE Date >= CURDATE() - INTERVAL 3 DAY ";
Notice I put the column name and table name in $sqlB
? Well, I tried substituting it now with PHP and this fails. It says syntax error, why?
$sqlC = "SELECT $column_name FROM $table_name WHERE Date >= CURDATE()-INTERVAL 3 DAY";
You can't have the minus sign in front of INTERVAL
. Use DATE_SUB
instead.
精彩评论