2012-10-04 84 views
2

可能重複:
PHP PDO bindParam with html content使用PDO來存儲HTML

我使用的是PDO準備語句插入/更新我的web應用程序一個新的博客文章。除了包含來自WYSIWYG編輯器的HTML標籤的文章主體之外,所有內容都被輸入到數據庫中。

假設$content包含<p>This is a test article</p>。它不會使用預先準備的語句插入。但是,如果我不使用準備好的語句,它會插入數據。

我該如何解決這個問題?

這裏是我的查詢:

$SQL = "UPDATE blog_articles SET topic_id = :topic_id, title = :title, "; 
$SQL .= "title_slug = :title_slug, description = :description, "; 
$SQL .= "keywords = :keywords, content = :content WHERE article_id = :article_id;"; 
$STH = $DBH->prepare($SQL); 

// other binds ... 
$STH->bindParam(':content', trim($content)); 
// other binds .. 

$STH->execute(); 

回答

3

這是回答here:使用

$pdo->bindValue(':html', $html, PDO::PARAM_STR); 

,而不是

$pdo->bindParam(:html, $html); 
+0

感謝奔,即工作。不要真的得到bindParam和bindValue的區別 - 更好地開始閱讀! – ShadowStorm

+0

NP。有關於它的討論[這裏](http://stackoverflow.com/questions/1179874/pdo-bindparam-versus-bindvalue),以及指向文檔的鏈接。 –