你如何通过" + interval 4"到bindParam

时间:2018-01-09 17:22:06

标签: php pdo

我正在尝试传递一个看起来像这样的变量" + interval 4"或" - 间隔5"本PDO声明。

$query = "INSERT INTO 
        " . $this->table_name . " (employee_id, work_date) 
        SELECT DISTINCT emp_num, 
        CURDATE() :test DAY FROM " . $this->table_name3 . "";

我的bindParam

$stmt->bindParam(":test", $this->interval); 

我不确定我是否应该使用bindValue很难搞清楚这一点。

这很好但我知道这不对

   $query = "INSERT INTO 
        " . $this->table_name . " (employee_id, work_date) 
        SELECT DISTINCT emp_num, 
        CURDATE() " . $this->interval .  " DAY FROM " . $this->table_name3 . "";

如果有帮助,这是整个功能

    function sqlbuild(){


    $query = "INSERT INTO 
        " . $this->table_name . " (employee_id, work_date) 
        SELECT DISTINCT emp_num, 
        CURDATE() " . $this->interval .  " DAY FROM " . $this->table_name3 . "";


    $stmt = $this->conn->prepare( $query );
    echo json_encode($stmt);


    $stmt->bindParam(":test", $this->interval); 
    //$stmt->bindParam(1, $this->interval); 

     echo json_encode($this-> interval);

    if($stmt->execute()){
        return true;
    }else{

        return false;
    }
}

0 个答案:

没有答案