是否在 MySQL 中创建触发器(通过 PHP)?

发布于 2024-09-13 03:32:23 字数 309 浏览 1 评论 0原文

MySQL 中的表有 1 个问题列:creation_date

在通过PHP插入新行时,我认为直接在查询中插入日期是正确的,MySQL必须自己做。

我是否需要执行触发器,或者按照预期使用 PHP 会更好? 你会怎么做?

PS: MySQL:如何创建触发器用于设置新行的创建日期

Table in MySQL have 1 problem column: creation_date.

During inserting a new row through PHP, I thought that there would be correct to insert the date directly in the query, MySQL has to do it himself.

Do I need to do the trigger, or it would be better to use PHP for this, as intended?
How would you have done to?

PS: MySQL: How to create trigger for setting creation date for new rows

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一梦等七年七年为一梦 2024-09-20 03:32:23

使用 TIMESTAMP DEFAULT CURRENT_TIMESTAMP 字段

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

Use TIMESTAMP DEFAULT CURRENT_TIMESTAMP field

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

一指流沙 2024-09-20 03:32:23

如果您为表创建触发器(或采用上面的建议),您将不必记住在 PHP 中执行此操作。当其他人创建另一个 PHP 来插入到同一个表中时,这种优势就会显现出来。

If you create a trigger for your table (or adopt the suggestion above) you won't have to remember to do it in your PHP. This advantage will show when someone else creates another PHP to insert into the same table.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文