下面的代码是不工作是应该的方式
$t = date('Y-d-m H:i:s',time());
$query = "INSERT INTO time VALUES('$t')";
if(mysql_query($query))
echo "Date and Time are added";
我创建了一个名为表time
只有一列now
和DATETIME
的数据类型 。 即使PHP脚本通过打印成功执行,在浏览器中"Date and Time are added"
。
该数据库没有更新它应该是的方式。 而不是当前的时间 ,它就会被初始化为默认值。
不要建议纠正问题的方式。
现在,您可以使用()
$query = "INSERT INTO `time` (`now`) VALUES (NOW())";
<?php
/* YOU NEED TO ESTABLISH FIRST A CONNECTION */
$con=mysqli_connect("Host","Username","Password","Database"); /* REPLACE THE NECESSARY HOST, USERNAME, PASSWORD, AND DATABASE */
if(mysqli_connect_errno()){
echo "Error".mysqli_connect_error();
}
$t = date('Y-d-m H:i:s');
$query = mysqli_query($con,"INSERT INTO time (now) VALUES ('$t')");
echo "Date and Time are added";
?>
这种格式尝试
$t = date('Y-m-d H:i:s');
$query = "INSERT INTO time (now) VALUES('$t')";
if(mysql_query($query))
echo "Date and Time are added";
要么
$query = "INSERT INTO time (now) VALUES(NOW())";
改变的$ T从价值
$t = date('Y-d-m H:i:s',time());
至
$t = date('Y-m-d H:i:s');
更妙的方法是编写插入这样的查询:
$query = "INSERT INTO `time` VALUES ('".date('Y-m-d H:i:s')."')";