Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
An easy way is to filter the incoming data.
Almost every DB driver now has built-in facilities for escaping dangerous characters, so everything that comes from the user can be filtered by ready-made functions.
In short, an example in PHP for mysqli, where $input is what came from the user, for example, through a form or otherwise.
If without protection it looks like this
$con=mysqli_connect("localhost","db_user","db_password","db_name");
$sql="select * from table where id=$input"
mysqli_query($con,$sql);
$con=mysqli_connect("localhost","db_user","db_password","db_name");
$sql = $mysqli->real_escape_string("select * from table where id=$input");
mysqli_query($con,$sql);
What kind of incoming data filtering do you perform?
Does using PHP PDO prevent SQL injection?
1. See here the rules of protection against external attacks.
2. Directly in the code: regex filtering of input data and prepared expressions for SQL queries.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question