Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
976 views
in Technique[技术] by (71.8m points)

php - real_escape_string vs. prepared statements

is there any reason to use one over the other in terms of speed and safety? Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Speed:

  • When you use bind parameters you can reuse the same query and query plan, just changing the parameters. When you build a query from strings the database has to reparse the statement.
  • With bind parameters the SQL parser also has less work to do. The parameters aren't escaped so the parsing is simpler.

Safety:

  • In my opinion, it is much easier to remember to use parameters than to remember to escape strings.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...