我是PDO的新手,剛開始使用它。我已經使用它插入,更新和刪除數據,並且使用基礎知識非常簡單。如何使PDO選擇查詢HTML安全嗎?
在測試環境中,我將一些HTML代碼插入數據庫。像:
<a href="google.com">Google</a>
<b>Bold text</b>
<u>Underlined text</u>
等等
我想這一點,因爲我用我的網站上爲用戶提供簡單的WYSIWYG編輯器,我想,以確保數據的安全性。
使用下列內容:
$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。所以文本是粗體的,而不是格式文本</b>。
我想知道是否有PDO的功能來阻止這一點。或者我只需要使用htmlentities和strip_tags?
在此先感謝
我不知道。非常感謝您的回覆。 – moonwalker 2010-11-01 15:42:23