Reputation: 333
I know nothing about SQL injection apart from the process to block it.
I was wondering, if an attacker would modify my prepared statement from:
$DB = $Con->prepare("SELECT * FROM Test WHERE username=?");
$DB->bind_param('s',$Username);
$DB->execute();
And his statement he entered was:
x' DROP TABLE Test
How would the bind/prepared statement process this request?
Would it return an error or continue? as the bind_param
links specific values to said SQL Statement?
Upvotes: 0
Views: 102
Reputation: 5896
Once you prepare a statement, it is pre-compiled. So any parameters you bind to it are sent as raw data and in no way could modify the SQL statement.
Your example would work fine, it would select all rows with the username x' DROP TABLE Test
.
Upvotes: 0
Reputation: 91742
No, the database would simply look for a record that has a username of x' DROP TABLE Test
so you would probably end up with an empty result set.
Upvotes: 1
Reputation: 5062
When using bind_param, the values will be escaped for you. You should still validate the data to make sure it's correct, but it's safe from injection
Upvotes: 0