2

I've seen the mySQL example here:How can I tell when a MySQL table was last updated?

But it's not working in mySQLi. I have this function to return the last time a specific table was updated (I am connected via another function that produces $conn), but it's not working. I want to run the function and return a date and time text. Any help is greatly appreciated!

My code:

function getDatabaseUpdateTimes($conn,$databaseName,$tableName){
    mysqli_select_db($conn,$databaseName);
    $query = "SELECT UPDATE_TIME 
        FROM   information_schema.tables
        WHERE  TABLE_SCHEMA = '$databaseName'
          AND  TABLE_NAME = '$tableName'";
    $updateTime=mysqli_query($conn, $query);  
    return $updateTime;
}
Community
  • 1
  • 1
Alex
  • 127
  • 1
  • 10

1 Answers1

1

Thanks @splash58 for the fix.

Final code:

function getTableUpdateTimes($conn,$databaseName,$tableName){
    mysqli_select_db($conn,$databaseName);
    $query = "SELECT UPDATE_TIME 
        FROM   information_schema.tables
        WHERE  TABLE_SCHEMA = '$databaseName'
          AND  TABLE_NAME = '$tableName'";
    $result=mysqli_query($conn, $query); 
    $row = mysqli_fetch_assoc($result); 
    $updateTime = $row['UPDATE_TIME'];
    return $updateTime;
}
Alex
  • 127
  • 1
  • 10