我有这个数据库(mysql):
我有代码:
$day = $app->request->post('day');
$startLocation = $app->request->post('startLocation');
$datum = new DateTime();
$startTime = $datum->getTimestamp(); //this line is IMPORTANT
global $user_id;
$db = new DbHandler();
// creating new task
$day_id = $db->createDay($user_id, $day, $startLocation, $startTime); ETC...
但是我无法将timestamp
数据提交到startTime
的{{1}}数据库中type timestamp
为什么呢?怎么做?
答案 0 :(得分:4)
如果您的列数据类型为TIMESTAMP
,则应为:
$datum = new DateTime();
$startTime = $datum->format('Y-m-d H:i:s');
注意:->getTimestamp()
会返回 unix时间戳
修改你的包装函数:
public function createDay($user_id, $day, $startLocation, $startTime) {
$stmt = $this->conn->prepare("INSERT INTO days(day,startLocation,startTime) VALUES(?,?,?)");
$stmt->bind_param('sss', $day, $startLocation, $startTime); // change the d into s in your types
$result = $stmt->execute();
$stmt->close();
}