When to close Prepared Statement

前端 未结 2 1690
眼角桃花
眼角桃花 2020-12-30 23:30

When to close prepared statements in PHP?

Example:

    $query = \"insert into web_reviews (title,added_date,reviewer_home_url,read_more_link,summary)         


        
相关标签:
2条回答
  • 2020-12-30 23:56

    I am unable to comment currently, so I am just providing an answer. When you run a prepared statement that queries the database for a result, it will not execute another query unless you remove the current result it is storing. $result = $stmt->get_result(). Secondly, If you will need the result from the first query to be saved so that you use it later, then I recommend using two result sets. The first stores the result from the first execution of $stmt and the second for the second execution. This might not answer the question directly, but it may help someone.

    0 讨论(0)
  • 2020-12-30 23:57

    That is a good use of close, especially since you are planning on making another query. With both PDO statements and MySQLi statements, I find that erring on the side of cleanliness is almost always for the best -- it removes potential bugs down the line.

    As to the gentlemen with 250 operations... I don't see what the real use case is. Why does he need to query the database 250 different times? Why can't he query the database once with 250 records? Or, more likely, why can't he query the database 25 times with 10 records?

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