-3

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.

potashin
  • 44,205
  • 11
  • 83
  • 107
Tristan12
  • 35
  • 5

2 Answers2

1

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."'"
potashin
  • 44,205
  • 11
  • 83
  • 107
1

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.

Marcos Pérez Gude
  • 21,869
  • 4
  • 38
  • 69