gpt4 book ai didi

php - 为什么我无法将 mysql 数据库中的时间戳与 php 中的当前时间进行比较?

转载 作者:行者123 更新时间:2023-11-29 19:06:32 26 4
gpt4 key购买 nike

sql表包含保存在timestamp中的时间 the format of time looks like this 2017-04-17 13:00:00

  <?php
include 'con.php';
$token = $_GET['key'];
$sql = "Select * FROM userlogin WHERE token = '$token'";
$result = mysqli_query($connect,$sql);
$user = mysqli_fetch_array($result);

if($user['time'] > 1800) { // check if the time is greater than 30 minutes then the link will expire.
exit("Link has expired");
}
?>

最佳答案

我会在 MySQL 中完成。

  <?php
include 'con.php';

$token = $_GET['key'];

$sql = "SELECT * FROM userlogin WHERE token = '$token' AND time BETWEEN TIMESTAMP(DATE_SUB(NOW(), INTERVAL 30 MINUTE)) AND TIMESTAMP(NOW())";
$result = mysqli_query($connect, $sql);
if (!mysqli_num_rows($result)) {
exit("Link has expired");
}

$user = mysqli_fetch_array($result);

// etc.
?>

关于php - 为什么我无法将 mysql 数据库中的时间戳与 php 中的当前时间进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43446347/

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