問題描述
正如標題所說,我在使用 bind_param() 時是否必須轉義用戶輸入,還是在內部完成?
As the title says, do I have to escape user input when using bind_param() or is that done internally?
謝謝.
推薦答案
不需要,綁定參數時不需要轉義數據以防止 SQL 注入.
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.
綁定參數時,不執行轉義(內部或其他方式).使用參數占位符準備 SQL 語句,并在執行時傳遞這些參數的值.
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.
數據庫知道什么是參數并相應地處理它們,而不是 SQL 值插值.
The database knows what parameters are and treats them accordingly as opposed to SQL value interpolation.
這篇關于在 MySQLi 上使用 bind_param() 時是否需要轉義數據以防止 SQL 注入?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!