Home > Backend Development > PHP Tutorial > php-addslashes, mysql_escape_string, mysql_real_escepe_string

php-addslashes, mysql_escape_string, mysql_real_escepe_string

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-23 14:36:06
Original
1042 people have browsed it

参考:

http://hi.baidu.com/catro/blog/item/c9e153e7e40f2f24b9382092.html

http://hi.baidu.com/devel83/blog/item/c367e781f026308af603a6d2.html

http://hi.baidu.com/nathena/blog/item/498655137ec83bd7f6039e06.html

 

 

从PHP手册入手..

手册上addslashes转义的字符是单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)。

mysql_real_escape_string转义的字符并没有被提到.只是说了一句

注意: mysql_real_escape_string() 并不转义 % 和 _


 

直接调用了MySql的C的API.mysql_real_escape_string()..

需要注意的是.这个函数在调用mysql_real_escape_string这个API之前.先是判断了是否连接上了数据库

CHECK_LINK(id);   //就是这句

所以这就意味着mysql_real_escape_string必须是连接数据库之后才能使用

 

以后也就用addslashes好了..暂时可以忘记掉mysql_real_escape_string了

 

 

-------------------------

 

 

 

总结一下:

addslashes() 是强行加;

mysql_escape_string不考虑连接的当前字符集。

 

mysql_real_escape_string()会判断字符集,但是对PHP版本有要求;函数用于转义SQL语句中的特殊字符,这个方法必须在连接数据库之后才能使用。

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template