我似乎无法将日期时间存储到数据库中。
public function add_post($username, $content) {
date_default_timezone_set("Asia/Manila");
$date = date("m/d/Y h:i A");
$final = strtotime($date);
$time_posted = date("m/d/Y h:i A", $final);
$sql =" INSERT INTO POSTS (username, post_content, time_posted)
VALUES ('$username','$content','$time_posted')";
return $this->db->query($sql);
}
在数据库中看起来像这样 0000-00-00 00:00:00
这是我的帖子表:Posts table
最佳答案
日期时间字段的格式应为:
$time_posted = date("Y-m-d H:i:s", $final);
关于php - 从 PHP 向 SQL 插入 DATETIME,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43147342/