What is the difference between get_result() and store_result() in php?

后端 未结 2 2074
北海茫月
北海茫月 2020-11-30 08:01

This is my code. I am checking if a user exists or not in a login/registration system:

public function userExist($email){
    $stmt = $this->conn->pre         


        
2条回答
  •  天涯浪人
    2020-11-30 08:48

    As usual, the accepted answer is too much focused on the the insignificant details from the question body, while a direct answer to the question stated in the title is somewhat eluding.

    There is also, sadly, a deleted answer, which, although being laconic, makes a perfect rule of thumb:

    Use get_result whenever possible and store_result elsewhere.

    Both functions load the pending resultset from the database to PHP process' memory whereas get_result() being much more versatile and therefore preferred.

    The only difference between get_result() and store_result() is that the former gets you a familiar mysqli_result resource/object which can be used to fetch the data using familiar fetch_row() / fetch_assoc() routines, as well as a slightly modern fetch_all() all of those are incomparably more convenient than bind_result() routine which is the only option with store_result().

    It could be noted that get_result() is only available when mysqlnd driver is used, which is not an issue in 2019 and beyond. If it's not available, you are probably to tick some checkbox in your shared host's configuration.

提交回复
热议问题