問題描述
在我頁面的頁腳中,我想添加諸如上次更新 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 theutimes()
function, to change the file timestamp.
頁面顯示:
- 使用
stat()
回讀文件修改時間.
- use
stat()
to read back the file modification time.
這篇關于如何判斷 MySQL 表的上次更新時間?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!