【问题标题】:SQL DateTime query not executing [duplicate]SQL DateTime 查询未执行 [重复]
【发布时间】:2016-06-24 22:34:59
【问题描述】:

此查询完美执行:

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

我从来没有从第二个查询中得到这个函数的返回。我不知道出了什么问题。

【问题讨论】:

    标签: php mysql sql codeigniter datetime


    【解决方案1】:

    您仍然需要将查询中的日期用引号括起来。位于变量内部并不意味着 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");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 2019-05-10
      • 2015-04-17
      • 2019-07-05
      • 1970-01-01
      相关资源
      最近更新 更多