[英]php does not insert current timestamp into mysql table?
Mysql table has a column DatePosted with the Datatype as TIMESTAMP
. Mysql表有一个DatePosted列,数据类型为
TIMESTAMP
。
I am trying to insert the current TIMESTAMP into the table using PHP. 我试图使用PHP将当前TIMESTAMP插入表中。 However the below code does not seem to work i get
0000-00-00 00:00:00
. 但是下面的代码似乎不起作用我得到
0000-00-00 00:00:00
。 Is the format wrong how do i get the current timestamp to be inserted in mysql 格式错误我如何获取当前时间戳插入mysql
TIMESTAMP.php file TIMESTAMP.php文件
date_default_timezone_set('America/Los_Angeles');
echo date("j of F Y, \a\\t g.i a", time());
mysqli_query($con,"INSERT INTO cfv_timestamp (DatePosted) VALUES ('".date("j F Y, \a\\t g.i a", time())."' )");
. 。
CREATE TABLE `cfv_timestamp (
`DatePosted` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
You should check mysql Timestamp format and change yours. 您应该检查mysql时间戳格式并更改您的格式 。
mysqli_query($con,"INSERT INTO cfv_timestamp (DatePosted)
VALUES ('".date("Y-m-d H:i:s", time())."' )");
Also you could set default value for Timestamp type CURRENT_TIMESTAMP 您还可以为Timestamp类型CURRENT_TIMESTAMP设置默认值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.