Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysqli_free_result necessary?

Tags:

I was looking through my code and read that it was recommened to use mysqli_free_result when your result object is not needed anymore. But after seeing that each query is outputed to the $result variable repeatedly throughout the script, I am wondering if mysqli_free_result would really be necessary. Seems like each time a query is ran the $result variable is already being wiped clean and set to a new result. Just curious if anyone has any input on this.

like image 743
JoJo Avatar asked Dec 30 '12 03:12

JoJo


2 Answers

Actually it’s necessary, because it might make a heavy load into the server when many requests are made. So preferably, you should use it.

Some other cases when you know that this query is followed by other query so you don’t have to use it.

like image 100
mamdouh alramadan Avatar answered Sep 28 '22 01:09

mamdouh alramadan


It’s never strictly necessary, but it's good practice to keep an eye on resources you’re using and know when you don't need them anymore.

It’s pretty minimal effort to drop in that extra line of code, so I would just do it every time you're finished with a result set. It has the added bonus of making it clear to someone reading your code when you’ve finished with a resource.

like image 23
Michael Mior Avatar answered Sep 28 '22 02:09

Michael Mior