为什么MySQL添加了撇号?

时间:2012-07-13 23:11:20

标签: php mysql codeigniter activerecord where

这是我正在构建的where子句:

 $where = "requesterid='".$memberid."' AND recieverid='".$tomemberid."' OR requesterid='".$tomemberid."' AND recieverid='".$memberid."'";

现在$memberid$tomemberid都是整数。这是我执行时的错误:

  

'where子句'

中的未知列'requesterid ='6''

SQL:

SELECT * FROM (`friendships`) WHERE `requesterid='6'` AND
recieverid='5' OR requesterid='5' AND recieverid='6'

为什么MySQL在数字6后添加撇号?我打印出$memberid并且在它之后/之前没有显示任何撇号或其他任何内容。我做错了什么?

1 个答案:

答案 0 :(得分:0)

如果这些是数值,则可以省略撇号

$where = "(requesterid=$memberid AND recieverid=$tomemberid) OR (requesterid=$tomemberid AND recieverid=$memberid)";