Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 php.net 上阅读了一条评论:
虽然bindValue()转义引号它不会转义“%”和“_”,所以使用时要小心LIKE。如果您不自己转义参数,则充满 %%% 的恶意参数可以转储您的整个数据库。PDO 不提供任何其他转义方法来处理它。
bindValue()
LIKE
那么它真的没有逃脱 % 和 _ 吗?什么是最好的解决方案?
正如评论所说,这实际上只是LIKE查询的问题。
这取决于您的数据库如何转义这些值。如果正常的反斜杠转义有效(如在 MySQL 中),则使用:
$like = addcslashes($like, "%_");
或者,最好是偷懒,把这些元字符去掉:
$like = strtr($like, "%_", " ");