Home >Database >Mysql Tutorial >关于mysql中特殊字符的使用注意事项_MySQL

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

WBOY
WBOYOriginal
2016-06-01 13:38:18878browse

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("_", "//_");

 

注意:因

Statement:
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