SQL DateTime查询未执行

时间:2016-06-24 22:34:59

标签: php mysql sql codeigniter datetime

此查询执行完美:

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");
}

我从未通过第二个查询从此函数返回。我不知道出了什么问题。

1 个答案:

答案 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");
}