MYSQL禁止ips,在不正确的时间间隔内被删除?

时间:2013-12-23 23:44:31

标签: php mysql sql

DELETE FROM     banned_users 
WHERE datetime  < (NOW() - INTERVAL '$ban' MINUTE) 
AND ban_length  != 'INF';

INF当然是禁令,但间隔如下

60 - 1 hour
and
1440 - 24 hours

然而,似乎这个查询(在页面加载的顶部从PHP运行)会删除所有不是“INF”的项目,而不是立即,而是从一分钟内我可以告诉的内容。

为什么发生这种情况?难怪我遇到重犯的问题!

$ban = $row['ban_length'];

分贝:

CREATE TABLE IF NOT EXISTS `banned_users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ip` varchar(200) NOT NULL,
  `username` varchar(22) NOT NULL,
  `ban_length` varchar(200) NOT NULL,
  `reason` text NOT NULL,
  `datetime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `ip` (`ip`)
)

回显查询

DELETE FROM banned_users 
WHERE datetime < (NOW() - INTERVAL 60 MINUTE) 
AND ban_length != 'INF';

此外,这是PHP代码

$result = mysql_query("SELECT * FROM banned_users WHERE  ip = '$ip'")or die(mysql_error());
$is_banned = FALSE;
while($row = mysql_fetch_assoc($result)) {
        $ban = $row['ban_length'];
        $is_banned = TRUE;
        $reason = $row['reason'];    

        mysql_query("
            DELETE FROM banned_users
            WHERE datetime < (NOW() - INTERVAL $ban MINUTE)
            AND ban_length != 'INF';")or die(mysql_error());
    }

    if($is_banned) {
        echo "banned";
    }

0 个答案:

没有答案