来自mysql表字段

时间:2018-05-30 20:19:51

标签: php mysql

我在mysql字段中创建了一个日志表名是表名,update_time update_time有时间戳。现在我想针对某些tbl名称选择max update_time

<?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);

?>

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

中给出

1 个答案:

答案 0 :(得分:1)

试试这个

<?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);

?>