加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

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

发布时间:2021-02-24 22:57:57 所属栏目:编程 来源:网络整理
导读:我的处事器上每分钟都有一个剧本运行,根基上可以完成一项cron使命,为我为一些伴侣建造的小游戏更新数据库中的某些变量. 我碰着的题目是该剧本仅运行某些查询,但无法更新其他查询.我已验证它正在毗连,但无法举办较量.任何辅佐,将不胜谢谢. 这是我今朝无法行使

我的处事器上每分钟都有一个剧本运行,根基上可以完成一项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 good
if ($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 
1555687200
1555777824
1555687500
loop started 
1555687227
1555777824
1555687527
最佳谜底 好吧,让我猜猜,剧本正在配置为全部人离线,对吗?
题目是您错过了UPDATE语句中的WHERE子句

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)和strtotime($then):$now和$then已经具有“ microtime”值,因此您可以这样做:

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

趁便说一句,纵然您没有行使任何REQUEST参数,我照旧提议您行使筹备好的语句.

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读