mysql转义单引号双引号,今天,mysql_real_escape_string()转义了单引号和双引号

$str = 'BEGIN This is a "quote" test. \'Single\' END';

echo $str . "\n";

echo mysql_real_escape_string($str);

// Outputs:

BEGIN This is a "quote" test. 'Single' END

BEGIN This is a \"quote\" test. \'Single\' END

Running PHP 5.3.2 on CentOS. As far as I can remember, mysql_real_escape_string() will only escape single quotes to prevent sql injections. Double quotes have nothing to do with that, because " does not start or end a string literal in MySQL!

This is causing backslashes to get inserted into the data! Something I clearly do not want.

解决方案

" does start a string in MySQL. (See: Strings)

Exception:

If the ANSI_QUOTES SQL mode is

enabled, string literals can be quoted

only within single quotation marks

because a string quoted within double

quotation marks is interpreted as an

identifier.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值