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\"
,本地主机生成正确的that's“ok”
。
可能是什么原因造成的?可能是一些 MySQL 设置吗?我还尝试使用 mysqli
而不是 PDO
,它做了同样的事情。
I have following piece of code which posts some data into database:
$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 ) );
I have MySQL version 5.1.47-community
on both localhost and staging / production server, but I'm getting different output on both of them. On localhost I'm running PHP 5.3.2
, production server has PHP 5.2.14
.
If I'm trying to post sentence that's "ok"
, on production it saves that\'s \"ok\"
, localhost produces correct that's "ok"
.
What could be causing this? Could it be some MySQL setting? I also tried using mysqli
instead of PDO
and it does the same thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些额外的反斜杠可以是 Magic Quotes,这样
that's "ok"
就变成那就“好吧”
。尝试禁用它们。These additional backslashes could be Magic Quotes so that
that's "ok"
becomesthat\'s \"ok\"
. Try to disable them.我认为,
magic_quotes_gpc
在生产服务器中是on
,而在本地主机中是off
。您可以使用
ini_set
命令进行设置。I suppose that
magic_quotes_gpc
ison
in production server and in localhost isoff
.You can set it using
ini_set
command.