简体   繁体   English

mysql插入如何转义斜线?

[英]How to escape slashes for mysql insert?

This is answered everywhere and I simply can't see what's wrong with my code: 到处都有答案,我根本看不出我的代码有什么问题:

print 'https://www.facebook.com/someURL'.'<br />';
print addslashes('https://www.facebook.com/someURL').'<br />';
print mysql_real_escape_string('https://www.facebook.com/someURL').'<br />';

Output is: 输出为:

https://www.facebook.com/someURL
https://www.facebook.com/someURL
https://www.facebook.com/someURL

Why are no slashes being added in any of these cases? 为什么在这些情况下都没有添加斜线?

Why are no slashes being added in any of these cases? 为什么在这些情况下都没有添加斜线?

You don't have any characters that need escaping in that string. 您不需要在该字符串中转义任何字符。


That said, addslashes is not suitable and mysql_real_escape_string (like all of mysql_ ) is obsolete , you should use a modern replacement and use prepared statements / bound arguments instead of manual string escaping. 就是说, addslashes不适合并且mysql_real_escape_string (像所有mysql_ )已经过时了 ,您应该使用现代替换方法,并使用准备好的语句/绑定参数,而不是手动转义字符串。

Because addslashes() returns a string with backslashes before characters that need to be escaped. 因为 addslashes()在需要转义的字符之前返回带反斜杠的字符串。 These characters are single quote ('), double quote ("), backslash () and NUL (the NULL byte). 这些字符是单引号('),双引号(“),反斜杠()和NUL(空字节)。

and your string doesnot contain any of the above mentioned characters. 并且您的字符串不包含上述任何字符。

From http://uk3.php.net/addslashes : http://uk3.php.net/addslashes

Returns a string with backslashes before characters that need to be escaped. 返回需要转义的字符前带有反斜杠的字符串。 These characters are single quote ('), double quote ("), backslash () and NUL (the NULL byte). 这些字符是单引号('),双引号(“),反斜杠()和NUL(空字节)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM