MySQL   发布时间:2022-05-15  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php / mysqli查询未执行某些查询且没有错误 大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我的服务器上每分钟都有一个脚本运行,基本上可以完成一项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
@H_675_12@
最佳答案@H_675_12@
好吧,让我猜猜,脚本正在设置为所有人离线,对吗?
问题是您错过了updatE语句中的WHERE子句

@H_217_9@mysqLi_query($conn,"updatE player_data SET is_online = 0");

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

@H_217_9@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参数,我还是建议您使用准备好的语句.@H_675_12@

大佬总结

以上是大佬教程为你收集整理的php / mysqli查询未执行某些查询且没有错误 全部内容,希望文章能够帮你解决php / mysqli查询未执行某些查询且没有错误 所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: