是否在 MySQL 中创建触发器(通过 PHP)?
MySQL 中的表有 1 个问题列:creation_date
。
在通过PHP插入新行时,我认为直接在查询中插入日期是正确的,MySQL必须自己做。
我是否需要执行触发器,或者按照预期使用 PHP 会更好? 你会怎么做?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 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
如果您为表创建触发器(或采用上面的建议),您将不必记住在 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.