views:

58

answers:

2

Hi,

I was wondering whether or not I've to call the $stmt->free_result() for after I've stored it's result with $stmt->store_result()? Could I rather just call $stmt->close() on the end?

The reason why I'm asking it is because when I call the $stmt->num_rows I've to call the $stmt->store_result() as said here: http://www.php.net/manual/en/mysqli-stmt.num-rows.php, but they don't call the $stmt->free_result() in their example. However, on the $stmt->store_result() they do: http://www.php.net/manual/en/mysqli-stmt.store-result.php.

+3  A: 

You do not have to expressly free the result, but you can if you'd wish. If you don't, the result will be freed when the statement handle goes out of scope.

Charles
Does it increase the performance if I free the result and the close it?
Richards
Probably not. Closing it effectively frees the result anyway. From the manual: "mysqli_stmt_close() also deallocates the statement handle. If the current statement has pending or unread results, this function cancels them so that the next query can be executed." Even then, you don't *need* to expressly free or close the result. Once the variable containing the result goes out of scope or is unset, the statement handle and everything attached to it disappears.
Charles
+1  A: 

PHP is pretty lenient with freeing resources. Any resources used by your script, such as SQL connections, will be freed when the script exits. Although it's good programming practice, unless you have many concurrent users there will be very little difference in performance.

Exception