PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi All,
My question today has to do with the way in which mysqli_close() has to be used... After having written quite a lot lines and functions of php code interacting with mysql database I realized that I was not using mysqli_close().
My questions are:
Do all mysqli_connect() have to have their correspondent mysqli_close() ? If Yes, when and where do you have to include it ? At the end of the script ? Right after the query to the database was run ? other ?
Any hint about the propper use of mysqli_close() it will be very much appreciated !
Well it should be used when you no longer want to use the connection. In other words you have no more queries to run.
I haven't run across any issues with leaving it out. You might have a problem if you needed to connect to two different databases.
I just put it at the bottom of my logic script. You don't want tot put it in your functions as it would be a waste to connect and close over and over again.
Now mysqli_free_result() should be used as soon as you are done with the result handle. This you'll want use in your functions before you return.
Thank You for your response, Gooney !
Honestly speaking I have not been using mysqli_close() and I did not see any adverse result, neither... Anyway, I guess I will follow your advise and use it at the end of the script...