将时间插入数据库 [英] Inserting time into database

查看:77
本文介绍了将时间插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码无法正常工作

The below piece of code isn't working the way it is supposed to

$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 的表现在只有一列现在 DATETIME 作为数据类型。即使 PHP 脚本通过打印添加日期和时间 在浏览器中成功执行了。


数据库未更新其应有的方式。而不是当前时间,它被初始化为默认值。


请提出解决问题的方法。

I have created a table named time with only one column now and DATETIME as datatype. Even though the PHP script executes successfully in the browser by printing "Date and Time are added".

The database isn't updating the way it is supposed to be. Rather than the current time, it gets initialized to default value.

Do suggest the way to rectify the problem.

推荐答案

您可以使用NOW()

You can use NOW()

$query = "INSERT INTO `time` (`now`) VALUES (NOW())";

这篇关于将时间插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆