我正在审查一些旧的PHP代码,其中MySql语句是硬编码的。我发现了一个带有奇怪where
子句的声明:
SELECT ...
FROM ...
WHERE 1970
AND Sale_Price.Server__ = `Server`.Server__
...
1970
条款中此where
号码的用途是什么?我以前从未见过这个。有特定的目的吗?
对我来说,它看起来像一个无害的错字/错误,我可以删除。你同意吗?
更新
以下是有关联接的更多信息:
SELECT ...
FROM `Server`, Product_Ref
LEFT JOIN Sale_Price ON Product_Ref.Product_Ref__ = Sale_Price.Product_Ref__
LEFT JOIN Purchase_Price ON Product_Ref.Product_Ref__ = Purchase_Price.Product_Ref__
LEFT JOIN Product_Category ON Product_Ref.Product__ = Product_Category.Product__
WHERE 1970
AND Sale_Price.Server__ = `Server`.Server__
AND Sale_Price.Date_Enter < NOW()
AND Sale_Price.Server__ IN ($this->salesServerIds)
答案 0 :(得分:1)
我们在评论中讨论了几种可能性:
隐藏真实条件:
... WHERE 1 = 1;
... WHERE 1;
... WHERE 1970;
-- All numbers except 0 evaluate to TRUE and will return all entries.
第二个选项是错误。如果您有版本控制(git,svn,cvs),您可以检查它何时被添加,以及是否是拼写错误或复制粘贴错误,我怀疑。拥有它的效果是你将获得所有结果;例如,您将获得 Sale_Price.Date_Enter 将来的条目。