本文介绍了PHP mysql自动插入时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有一个带有这些字段的表名auto_parts.id, part, price, timestamp
我这样通过php插入了新行:
Say I have a table name auto_parts with these fields.id, part, price, timestamp
and I insert a new row via php as so:
$query = "insert into auto_parts(id, part, price, timestamp)
values(1, 'axle', 200)"
mysql_query($query);
将自动添加时间戳.还是我必须自己为时间戳插入一个值?
will that automatically add the timestamp.Or do I have to insert a value for timestamp myself?
推荐答案
您需要做的是声明timestamp
为sql类型
What you need to do is declare timestamp
to be of type in your sql
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
并将查询修改为
$query = "insert into auto_parts(id, part, price)
values(1, 'axle', 200)"
mysql_query($query);
这篇关于PHP mysql自动插入时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!