Can parameterized statement stop all SQL injection?

后端 未结 12 1908
轻奢々
轻奢々 2020-11-30 20:31

If yes, why are there still so many successful SQL injections? Just because some developers are too dumb to use parameterized statements?

12条回答
  •  难免孤独
    2020-11-30 21:13

    First my answer to your first question: Yes, as far as I know, by using parameterized queries, SQL injections will not be possible anymore. As to your following questions, I am not sure and can only give you my opinion on the reasons:

    I think it's easier to "just" write the SQL query string by concatenate some different parts (maybe even dependent on some logical checks) together with the values to be inserted. It's just creating the query and executing it. Another advantage is that you can print (echo, output or whatever) the sql query string and then use this string for a manual query to the database engine.

    When working with prepared statements, you always have at least one step more: You have to build your query (including the parameters, of course) You have to prepare the query on the server You have to bind the parameters to the actual values you want to use for your query You have to execute the query.

    That's somewhat more work (and not so straightforward to program) especially for some "quick and dirty" jobs which often prove to be very long-lived...

    Best regards,

    Box

提交回复
热议问题