为了账号安全,请及时绑定邮箱和手机立即绑定

php / mysqli查询未执行某些查询且没有错误

php / mysqli查询未执行某些查询且没有错误

PHP
蝴蝶刀刀 2021-05-03 12:09:04
我的服务器上每分钟都有一个脚本运行,基本上可以完成一项cron工作,以便为我为一些朋友制作的小游戏更新数据库中的某些变量。我遇到的问题是该脚本仅运行某些查询,但无法更新其他查询。我已验证它正在连接,但无法进行比较。任何帮助,将不胜感激。这是我目前无法通话的电话。//Query server$query = "SELECT id, usr, dt, is_online FROM player_data WHERE is_online =1";$result = mysqli_query($conn, $query);// If connection is goodif ($result = mysqli_query($conn, $query))     {        echo "Connected </br>";    /* fetch associative array */    while ($row = mysqli_fetch_assoc($result))         {            //Get time of NOW, and time of last activity            echo "loop started </br>";            $now = strtotime(date("Y-m-d h:i:s", strtotime("now")));            $before = strtotime(date("Y-m-d h:i:s", strtotime($row['dt'])));            //Add five minutes to the last activity            $then = $before + (60 * 5);            //Display the times            echo $before . "</br>";            echo $now . "</br>";            echo $then . "</br>";            //determine if the time now is more then 5 minutes after the last activity            if (strtotime($now) > strtotime($then))                {                    //set user to offline if more then 5 minutes has passed.                    mysqli_query($conn, "UPDATE player_data SET is_online = 0");                    echo "1.User: " . $row['usr'] . "</br>";                    echo "1.Database: " . $row['dt'] . "</br>";                    echo "1.System: " . date('Y-m-d H:i:s') . "</br>";                    echo "Now: " . $now . "</br>";                    echo "Before: " . $before . "</br>";                    echo "then: " . $then . "</br>";                }        }    }`````````````````````````````````````````````````````````````````````````this should set anyone who has not been active in the last 5 minutes to is_online = 0 but does not.This is the actual output as of right now with the last activity being more then 1.5 hours earlier.Connected loop started 155568720015557778241555687500loop started 155568722715557778241555687527
查看完整描述

2 回答

?
qq_花开花谢_0

TA贡献1835条经验 获得超7个赞

好吧,让我猜猜,脚本正在设置为所有人离线,对吗?事实是您错过了WHERE我们UPDATE声明中的条款

mysqli_query($conn, "UPDATE player_data SET is_online = 0");

因此,最好回顾一下该部分。应该是这样的

mysqli_query($conn, "UPDATE player_data SET is_online = 0 WHERE id = " . $row['usr']);

另外,也不需要比较strtotime($now)and strtotime($then)$now和and$then已经具有“ microtime”值,因此您可以这样做:

if ($now > $then) {
    //your code here
    }

顺便说一句,即使您没有使用任何REQUEST参数,我也建议您使用准备好的语句。


查看完整回答
反对 回复 2021-05-07
  • 2 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信