【发布时间】:2011-05-03 11:41:37
【问题描述】:
我是 PDO 的新手,刚开始使用它。我已经使用它插入、更新和删除了数据,而且使用起来非常简单。
在测试环境中,我向数据库中插入了一些 HTML 代码。喜欢:
<a href="google.com">Google</a>
<b>Bold text</b>
<u>Underlined text</u>
等等……
我正在尝试这个,因为我在我的网站上为用户使用了一个简单的所见即所得编辑器,并且我想确保数据是安全的。
使用以下内容:
$stmt = $dbh->prepare("SELECT * FROM naruto WHERE id = :id AND name = :name");
/*** bind the paramaters ***/
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
$stmt->bindParam(':name', $name, PDO::PARAM_STR, 5);
/*** execute the prepared statement ***/
$stmt->execute();
/*** fetch the results ***/
$result = $stmt->fetchAll();
/*** loop of the results ***/
foreach($result as $row)
{
echo $row['id'].'<br />';
echo $row['name'];
echo $row['image'];
}
其中 name 是不同的 HTML 代码,HTML 只是被执行。所以文本是粗体的,而不是文本格式。
我想知道 PDO 是否有阻止这种情况的功能。还是我只需要使用 htmlentities 和 strip_tags?
提前致谢
【问题讨论】: