Home  >  Article  >  Backend Development  >  How to database escape PHP?

How to database escape PHP?

Guanhui
GuanhuiOriginal
2020-07-22 09:48:222895browse

How to database escape PHP?

PHP How to database escape?

1. Before PHP7, you can use the function "mysql_escape_string()" to escape the data;

mysql_escape_string ( string $unescaped_string ) : string

2. After PHP7, you can use the "mysqli_real_escape_string()" function to escape the data. .

mysqli_real_escape_string ( mysqli $link , string $escapestr ) : string

3. Use the function "addslashes()" to escape

addslashes ( string $str ) : string
function myaddslashes($data)
{
    if(false == get_magic_quotes_gpc())
    {
        return addslashes($data);//未启用魔术引用时,转义特殊字符
    }
    return $data;
}

Recommended tutorial: "PHP"

The above is the detailed content of How to database escape PHP?. For more information, please follow other related articles on the PHP Chinese website!

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