从mysql表字段检索时间戳

rt4zxlrg  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(412)

我在mysql中创建了一个日志表,表名是表名,update\u time update\u time有时间戳。现在我想根据特定的tbl名称选择最长更新时间

<?php

      $con=mysqli_connect("localhost","root","","db");

// Check connection
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$mysqltime = $con->query("SELECT Max(update_time ) FROM log_tbls WHERE table_name = 'abc'");
$timestamp = strtotime($mysqltime);
echo date("Y-m-d H:i:s", $timestamp);

?>

我有一个错误strotime()期望参数1是字符串,对象在

chhkpiq4

chhkpiq41#

试试这个

<?php

  $con=mysqli_connect("localhost","root","","db");

  if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

  $mysqltime = mysqli_query($con, "SELECT Max(update_time) as updateTime FROM log_tbls WHERE table_name = 'abc'");
  $m = mysqli_fetch_array($mysqltime);
  $timestamp = strtotime($m['updateTime']);
  echo date("Y-m-d H:i:s", $timestamp);

?>

相关问题