Home > Database > Mysql Tutorial > body text

关于mysql中特殊字符的使用注意事项_MySQL

WBOY
Release: 2016-06-01 13:38:18
Original
861 people have browsed it

bitsCN.com


关于mysql中特殊字符的使用注意事项

 

1 直接拼成sql情况    

●如果是“=”,需要转义的字符为’ /

'转为''

/转为////

具体代码如下:

sql = sql.replace("'", "''");

sql = sql.replace("//", "////");

●如果是"like",需要转义的字符为‘ / % _

'转为''

/转为////////(注意需要8个,汉)

%转为//%

_转为//_

具体代码如下:

sql = sql.replace("'", "''");

sql = sql.replace("//", "////////");

sql = sql.replace("%", "//%");

sql = sql.replace("_", "//_");

2 使用预处理sql情况

●只有使用"like"时才需要转义

/转为////

%转为//%

_转为//_

sql = sql.replace("//", "////");

sql = sql.replace("%", "//%");

sql = sql.replace("_", "//_");

 

注意:因

Related labels:
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template