现在是凌晨 12:30,我已经连续编码了 9 个小时。我真的需要完成这个项目,但是 MySQL 打乱了我的最后期限。你能帮我检查一下这个片段,看看你是否能找出问题所在吗?
PHP/MySQL 查询
$q = $this->db->query("SELECT * FROM bans WHERE ip='".$ip."'");
不断返回以下错误...
MYSQL Error [Oct 6th, 2010 11:31pm CDT]
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM bans WHERE ip='206.53.90.231'' at line 1 (1064)
我没有发现查询有任何问题。我什至尝试了包含变量 $ip 的不同方法,但无济于事。
编辑:
只是在这里添加,我数据库中的 ip 列是一个 varchar(255)。
编辑 2:
这是整个受影响的代码。请记住,这都在一个类中。如果我遗漏了什么,请告诉我。
来自另一个函数的行
if($this->isBanned($_SERVER['REMOTE_ADDR'])===true) { return json_encode(array('error'=>'You are banned from this ShoutBox.')); }
受影响的功能
function isBanned($ip) {
$q = $this->db->query("SELECT * FROM bans WHERE ip='".$ip."'"); $num = $this->db->affected_rows;
if($num>0) { $row = $this->db->fetch_array($q); if(($row['expires'] < time()) && ($row['expires'] !== 0)) { $this->unbanUser($ip,'internal'); return false; } return true; } return false;
}
unbanUser 函数
function unbanUser($ip,$t='box') {
$q = $this->db->query("SELECT * FROM bans WHERE ip='".$ip."'"); $num = $this->db->affected_rows; if($num>0) { $q = $this->db->query("DELETE * FROM bans WHERE ip='".$ip."'");
return (($t=='box') ? json_encode(array('status'=>'removed')) : true); } else { return (($t=='box') ? json_encode(array('error'=>'Unable to locate the user.')) : true); }
}
最佳答案
我认为可能是 是您的 DELETE
语句导致了错误。
去掉DELETE
后面的*
就可以了。
关于php - 这个 MySQL 查询有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3878720/