转义字符串
我正在使用 PDO,并且印象中要准备转义撇号,但我发现事实并非如此。我用什么来转义撇号字符串?
$sql = 'SELECT test FROM test WHERE id = :id';
$sth = $dbh->prepare($sql);
$sth->execute(array(':id' => 1));
$red = $sth->fetchAll();
I'm using PDO and was under the impression that prepare escaped apostrophes but I can see that isn't the case. what do I use to escape my strings for apostrophes?
$sql = 'SELECT test FROM test WHERE id = :id';
$sth = $dbh->prepare($sql);
$sth->execute(array(':id' => 1));
$red = $sth->fetchAll();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我怀疑虽然您可能使用准备好的语句,但您没有绑定参数。例如,
您应该使用
或者 至少
这是使用命名参数,但您也可以使用
?
作为占位符来使用位置参数I suspect that whilst you might be using a prepared statement, you are not binding parameters. For example, instead of
You should use
or at least
This is using named parameters but you can also use positional ones using
?
as a placeholder我不确定我是否理解你的问题,但这可能有助于 PDO 转义:
I am not sure I understand your question, but this might help with PDO escaping:
我怀疑您没有正确使用准备好的语句,或者您的代码有问题。
文档 特别指出:
I Suspect you are not using preparred statements correctly, or there is something wrong with your code.
The docs specifically states: