Home  >  Article  >  php教程  >  一个登陆安全的函数PHP mysql

一个登陆安全的函数PHP mysql

WBOY
WBOYOriginal
2016-06-06 19:48:591266browse

定义和用法 mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。 下列字符受影响: \x00 \n \r \ ' \x1a 如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。 语法 mysql_real_escape_string(string,connection) 参数

定义和用法

mysql_real_escape_string() 函数转义 SQL 语句中使用的字符串中的特殊字符。

下列字符受影响:

  • \x00
  • \n
  • \r
  • \
  • '
  • "
  • \x1a

如果成功,则该函数返回被转义的字符串。如果失败,则返回 false。

语法

mysql_real_escape_string(string,connection)
参数 描述
string 必需。规定要转义的字符串。
connection 可选。规定 MySQL 连接。如果未规定,则使用上一个连接。

说明

本函数将 string 中的特殊字符转义,并考虑到连接的当前字符集,因此可以安全用于 mysql_query()。

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