php – ‘创建于’和’更新在’字段

前端之家收集整理的这篇文章主要介绍了php – ‘创建于’和’更新在’字段前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这似乎是一个非常简单的一个,但我很难想出来.我想要一个列在我的数据库中列出了创建一个记录,另一列说明何时更新.这是我的理解,我应该能够使用所有这一切只使用 MySQL.所有的帮助是赞赏:)

这个臭味还没有回答,原因我已经开始错过Ruby on Rails …

您可能需要使用Datetime数据类型和Timestamp数据类型的组合.我将使用DEFAULT NOW()将我创建的列设置为DateTime,将已更新的列设置为具有DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP属性的Timestamp.

以下是Timestamp dt的文档:

http://dev.mysql.com/doc/refman/5.0/en/timestamp.html

In a CREATE TABLE statement,the first TIMESTAMP column can be declared in any of the following ways:

With both DEFAULT CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP clauses,the column has the current timestamp for its default value,and is automatically updated.

With neither DEFAULT nor ON UPDATE clauses,it is the same as DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP.

With a DEFAULT CURRENT_TIMESTAMP clause and no ON UPDATE clause,the column has the current timestamp for its default value but is not automatically updated.

With no DEFAULT clause and with an ON UPDATE CURRENT_TIMESTAMP clause,the column has a default of 0 and is automatically updated.

With a constant DEFAULT value,the column has the given default and is not automatically initialized to the current timestamp. If the column also has an ON UPDATE CURRENT_TIMESTAMP clause,it is automatically updated; otherwise,it has a constant default and is not automatically updated.

原文链接:https://www.f2er.com/php/140029.html

猜你在找的PHP相关文章