我有下面这段代码一些数据帖到数据库:PHP转义编码报价
$post = trim($post);
$post = htmlentities($post, ENT_QUOTES, null, false);
$statement = "INSERT INTO table (row) VALUES (:message)";
$prepared_posts = $pdo->prepare($statement);
$prepared_posts->execute(array(':message' => $post));
我的MySQL版本5.1.47-community
在本地主机都和分期/生产服务器,但我发现了两个不同的输出其中。在本地主机上我正在运行PHP 5.3.2
,生产服务器有PHP 5.2.14
。
如果我想发布一句话that's "ok"
,在生产上它会保存that\'s \"ok\"
,localhost会生成正确的that's "ok"
。
这可能是什么原因造成的?它可能是一些MySQL设置?我也尝试使用mysqli
而不是PDO
,它也做同样的事情。
感谢您的快速解决方案! – 2010-10-10 17:12:19