此查询执行完美:
public function alter_orders()
{
return $this->db->query("UPDATE `orders` SET `Ready_Date_Time` = '2016-06-02 00:00:00', `Delivery_Date_Time` = '2016-06-01 00:00:00', `Status` = $Status WHERE `orders`.`Order_ID` = $primary_key;");
}
但这不是:
public function alter_orders()
{
$primary_key = 1;
$Ready_Date_Time = "2016-06-02 00:00:00";
$Delivery_Date_Time = "2016-06-02 00:00:00";
$Status = 1;
return $this->db->query("UPDATE `orders` SET `Ready_Date_Time` = $Ready_Date_Time, `Delivery_Date_Time` = $Delivery_Date_Time, `Status` = $Status WHERE `orders`.`Order_ID` = $primary_key");
}
我从未通过第二个查询从此函数返回。我不知道出了什么问题。
答案 0 :(得分:4)
您仍需要在查询中包含查询中的日期。内部变量并不意味着SQL不需要它们。变量'在执行查询之前,值被插入到查询中,就MySQL而言,它是纯文本文本。
public function alter_orders()
{
$primary_key = 1;
$Ready_Date_Time = "2016-06-02 00:00:00";
$Delivery_Date_Time = "2016-06-02 00:00:00";
$Status = 1;
return $this->db->query("UPDATE `orders` SET `Ready_Date_Time` = '$Ready_Date_Time', `Delivery_Date_Time` = '$Delivery_Date_Time', `Status` = $Status WHERE `orders`.`Order_ID` = $primary_key");
}