Home > Article > Backend Development > The most complete way to prevent SQL injection
Used as follows:
?
1 2 3 |
|
Use
mysql_real_escape_string()
as a wrapper around user input to avoid any malicious SQL injection in user input.
(2) Turn on magic_quotes_gpc to prevent SQL injection
There is a setting in php.ini: magic_quotes_gpc = Off
This is turned off by default. If it is turned on, it will automatically convert the SQL query submitted by the user,
For example, converting ' to ', etc., plays a significant role in preventing sql injection.
If magic_quotes_gpc=Off, use the addslashes() function
(3) Custom function
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
|