Show MySQL Table Update Date & Time on Web Page with SHOW TABLE STATUS FROM

I had a project where I had to display on the web page when a particular MySQL table was last updated. After some research, I found MySQL's SHOW TABLE STATUS.
Below is an example of how I did it using PHP and MySQL:

$host = "hostname";

$user = "username";

$password = "*******";

$db_name = "db_name";

$connect = @mysql_connect($host, $user, $password) or die ( mysql_error() );

@mysql_select_db($db_name, $connect) or die( mysql_error() );

$info = mysql_fetch_array(mysql_query("SHOW TABLE STATUS FROM `db` LIKE 'table_name'"));

$updated = strtotime($info["Update_time"]);

$last = date("h:i:s A", $updated);

echo "Last Updated: $last";

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.