I learned that using prepared statement (parameterized queries) can be used for preventing SQL injection attack with few exceptions mentioned in this post: Are PDO prepared statements sufficient to prevent SQL injection?.
My question is how a prepared statement prevents SQL injection? What I've learned so far:
When using parameterized query, the client sends the query to server for preparation (optimization) without any data, and later, parameters (user input or any) will be sent to the server so that the user data resides outside the original query.
When using prepared query, if user data is not escaped, then it will not prevent any SQL injection.
For this reason, I failed to test the example because using execute()
, bind_param()
, binVlaue()
, binParam()
are all escaping the data when used so that we can't send un-escaped data with them for testing the safety of prepared statement with un-escaped parameters.