gpt4 book ai didi

php - 从 mysql 表字段检索时间戳

转载 作者:行者123 更新时间:2023-11-29 10:13:07 25 4
gpt4 key购买 nike

我在mysql中创建了一个日志表,字段名称是表名,update_time update_time有时间戳。现在我想针对某些表名称选择最大 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 为字符串,对象在

中给出

最佳答案

试试这个

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

?>

关于php - 从 mysql 表字段检索时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50612787/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com