The content of this article is about the method of preventing SQL injection in PHP Mysql. It has a certain reference value. Now I share it with you. Friends in need can refer to
Related mysql video tutorial recommendations: " mysql tutorial》
Method 1:
mysql_real_escape_string -- Escape special characters in the string used in the SQL statement, taking into account the current connection character set!1 2 3 |
|
Method 2:
Open 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, such as converting ' to \', etc., which plays a significant role in preventing SQL injection.
If magic_quotes_gpc=Off, use the addslashes() function.
Method 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
The above is the detailed content of How to prevent SQL injection in PHP+Mysql. For more information, please follow other related articles on the PHP Chinese website!