PDO: Cost of Calling prepare() in a loop?

后端 未结 1 1346
北荒
北荒 2021-01-13 12:49

I\'m writing a database class for my website with functions such as fetchOne, fetchAll which prepare, execute (+ bind), and fetch the query all in

相关标签:
1条回答
  • 2021-01-13 13:46

    you would not want to "re-prepare" the same query multiple times. this is the purpose of the prepare statement. you prepare it once, bind the variable(s), then you simply switch the variables' values and re-execute each iteration of the loop.

    http://www.php.net/manual/en/pdostatement.bindparam.php

    doing it this way will greatly increase your performance over alternative methods.

    0 讨论(0)
提交回复
热议问题