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

后端 未结 2 1599
旧巷少年郎
旧巷少年郎 2021-01-13 01:01

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

Thank you.

2条回答
  •  星月不相逢
    2021-01-13 01:29

    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.

提交回复
热议问题