2

可能重复:
带有 html 内容的 PHP PDO bindParam

我正在使用 PDO 准备好的语句为我的网络应用程序插入/更新一篇新的博客文章。除了文章正文(包含来自所见即所得编辑器的 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();
4

1 回答 1

3

这在这里得到了回答:使用

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

代替

$pdo->bindParam(:html, $html);
于 2012-10-04T17:13:27.213 回答