$stmt->close() vs $stmt->free_result()

前端 未结 2 553
刺人心
刺人心 2020-12-24 13:08

I am trying to clarify the difference between $stmt->close() and $stmt->free_result() when finalizing a prepared mysqli st

2条回答
  •  囚心锁ツ
    2020-12-24 13:42

    PHP will end your connection and free the resource after it finishes running;

    mysqli::close Closes a prepared statement.

    Since the number of total connections available is limited, freeing the resource the second you're done with it is a good practice.

    And

    mysqli_stmt::free_result Frees stored result memory for the given statement handle.

    it's good practice to free explicitly the resource when you don't need them anymore. it might avoid make a heavy load into the server when many requests are made at the same time.

    Both aren't never strictly necessary to invoke, and is a good practice the use of both.

提交回复
热议问题