如何判断mySQLi表的上次更新时间?

时间:2016-06-04 22:16:12

标签: php mysqli

我在这里看到了mySQL示例:How can I tell when a MySQL table was last updated?

但它不适用于mySQLi。我有这个函数来返回特定表的最后一次更新(我通过另一个生成$ conn的函数连接),但它不起作用。我想运行该函数并返回日期和时间文本。非常感谢任何帮助!

我的代码:

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;
}

1 个答案:

答案 0 :(得分:1)

感谢@ splash58的修复。

最终代码:

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;
}