使用php mysqli函数在mysql中插入日期

时间:2014-12-07 23:15:39

标签: php mysql mysqli

我在后端有这个REST api代码:

public function createDay($user_id, $day, $startLocation, $startTime) {
        $stmt = $this->conn->prepare("INSERT INTO days(day,startLocation,startTime,dayDate) VALUES(?,?,?,?)");
        $stmt->bind_param("ssss", $day, $startLocation, $startTime, $dayDate);
        $result = $stmt->execute();
        $stmt->close();

        if ($result) {
            // task row created
            // now assign the task to user
            $new_day_id = $this->conn->insert_id;
            $res = $this->createUserDay($user_id, $new_day_id, $dayDate);
            if ($res) {
                // task created successfully
                return $new_day_id;
            } else {
                // task failed to create
                return NULL;
            }
        } else {
            // task failed to create
            return NULL;
        }
    }

和函数createDay:

public function createUserDay($user_id, $day_id, $dayDate) {
        $stmt = $this->conn->prepare("INSERT INTO user_days(user_id, day_id, $dayDate) values(?, ?, ?)");
        $stmt->bind_param("iis", $user_id, $day_id, $dayDate);
        $result = $stmt->execute();

        if (false === $result) {
            die('execute() failed: ' . htmlspecialchars($stmt->error));
        }
        $stmt->close();
        return $result;
    }

}

这是dbhandler文件,现在我有一个问题 -

我用

 $new_day_id = $this->conn->insert_id; 

获取当前数据的ID,以及我如何将$dayDate用于createUserDay函数

所以我需要获得$ dayDate并将其用于createUserDay函数,有什么办法吗?

0 个答案:

没有答案