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!