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

How to database escape PHP?

Guanhui
Release: 2023-03-02 20:36:01
Original
2986 people have browsed it

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
Copy after login

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
Copy after login

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

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

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!

Related labels:
php
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