Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need to escape data to protect against SQL injection when using bind_param() on MySQLi?

As the title says, do I have to escape user input when using bind_param() or is that done internally?

Thank you.

like image 989
Francisc Avatar asked Sep 13 '11 23:09

Francisc


1 Answers

No, you do not need to escape data to protect against SQL injection when binding parameters.

This does not absolve you from validating said data though.

When binding parameters, there is no escaping performed (internally or otherwise). An SQL statement is prepared with parameter placeholders and values for these are passed at execution time.

The database knows what parameters are and treats them accordingly as opposed to SQL value interpolation.

like image 162
Phil Avatar answered Sep 28 '22 01:09

Phil