I want to get the last time my database was updated, so I use this query in my PHP code:
$query = mysqli_query($mysqli, "SELECT UPDATE_TIME
FROM information_schema.tables
WHERE TABLE_SCHEMA = 'map_db'
AND TABLE_NAME = ".$objects_tab."");
$lastUpdateTime = mysqli_fetch_array($query);
echo "<div id ='lastUpdate'>".$lastUpdateTime."</div>";
For some reason the query won't work, does anyone know whats the problem?
It works when I do other queries so its not the $mysqli
connect variable or the table name variable that's wrong.
Table name value should be wrapped in single quotes:
"SELECT UPDATE_TIME
FROM information_schema.tables
WHERE TABLE_SCHEMA = 'map_db'
AND TABLE_NAME = '".$objects_tab."'"
I think that's incorrect. mysql_fetch_array()
returns an array of results. You must to modify like this:
$rows = mysqli_fetch_array($query);
echo "<div id ='lastUpdate'>".$rows['lastUpdateTime']."</div>";
Assuming lastUpdateTime
as the key in the database.