Recently in the use of the framework is still a little uneasy, do not know the framework of the designers have not considered the problem of sql-injection, I need to do in the top floor needs to do some necessary filtering and so on, so I deliberately to StackOverflow to see the next, really benefited a lot, Then I went to see the internal method of the DB Library under the framework, and then it was more reassuring. Share some of the programs that PHP programmers at home and abroad are dealing with sql-injection.
Abroad is generally recommended, as long as you are using the query should be done two points: 1. prepared Statements(Ready statement) 2. Parameterized queries (parameterized query request).
I didn't understand what that meant at first, but then I looked at them for example and I probably knew it. For a more secure SQL, you need to start by preparing the variables for the query. Such as:
$name = $_post[' name ']; $sql = ' select ' from user where name '. $name;
Then the best thing is to deal with $name first,
$name = mysql_real_escape_string ($_post[' name ');//
Then, let the requested variable become a parameter, not the SQL language itself.
$sql = ' Select ' from user where name=\ '. $name. ' \‘‘;
Of course, this kind of writing is still relatively rough.
Therefore, it is generally recommended to use PDO or the mysqli prepare () Excute () method.
$stmt = $pdo->prepare (' SELECT * from user WHERE name =: Name '), $stmt->execute (Array (' name ' = = $name));
About PDO::p Repare ()
The advantage of this is that you no longer need to worry that the query request will insert some SQL statements, as these statements will be treated as request variables (a string or a number) and no longer be mistaken for the SQL language itself. This can greatly reduce the chances of SQL injection.
PHP's precautions for SQL injection.