如何判断 MySQL 表的最后更新时间? [英] How can I tell when a MySQL table was last updated?

查看:62
本文介绍了如何判断 MySQL 表的最后更新时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我页面的页脚中,我想添加类似上次更新 xx/xx/200x"的内容,此日期是某个 mySQL 表的最后一次更新时间.

In the footer of my page, I would like to add something like "last updated the xx/xx/200x" with this date being the last time a certain mySQL table has been updated.

最好的方法是什么?是否有检索上次更新日期的功能?每次需要这个值时我都应该访问数据库吗?

What is the best way to do that? Is there a function to retrieve the last updated date? Should I access to the database every time I need this value?

推荐答案

在更高版本的 MySQL 中,您可以使用 information_schema 数据库来告诉您何时更新了另一个表:

In later versions of MySQL you can use the information_schema database to tell you when another table was updated:

SELECT UPDATE_TIME
FROM   information_schema.tables
WHERE  TABLE_SCHEMA = 'dbname'
   AND TABLE_NAME = 'tabname'

这当然意味着打开与数据库的连接.

This does of course mean opening a connection to the database.

另一种选择是在 MySQL 表更新时触摸"特定文件:

An alternative option would be to "touch" a particular file whenever the MySQL table is updated:

关于数据库更新:

  • O_RDRW 模式打开您的时间戳文件
  • 关闭再次
  • Open your timestamp file in O_RDRW mode
  • close it again

或者

  • 使用 touch()utimes() 函数的 PHP 等效项,用于更改文件时间戳.
  • use touch(), the PHP equivalent of the utimes() function, to change the file timestamp.

页面显示:

  • 使用stat()回读文件修改时间.
  • use stat() to read back the file modification time.

这篇关于如何判断 MySQL 表的最后更新时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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