Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
Most of the time, PHP automatically frees up memory when resources are no longer needed. So it's common practice to leave the job of freeing resources to PHP's garbage collection. But with MySQLi there are times when you need to free resources explicitly, and in fact it's recommended you always do so. There are three methods that free up database resources in MySQLi, close, free and free_result. Let's take a look how they're used.
With a prepared statement calling the With the MySQLi result object, all three have the same meaning. close method, destroys the statement object, They free the memory associated with the result set and destroy the result object. and cancels any results that haven't yet been retrieved from the database. Because prepared statements aren't buffered by default, you need to call the Close method before attempting to submit another query if the result set hasn't been completely consumed. Alternatively, use the store _result method to buffer the result set. Calling the free_result method frees up the memory associated with a result set that's been buffered using store_result.
Alternatively, use the store _result method to buffer the result set. Calling the free_result method frees up the memory associated Unlike close, it doesn't destroy the statement object, so you with a result set that's been buffered using store_result. can use it to prepare and execute another prepared statement. Those close method also closes a database connection. That's how the close, free, and free result methods are used, but do you really need to bother? The one situation where it's vital to free resources is to avoid the commands out of sync error.
is to avoid the commands out of sync error. This happens when you have unused results in an unbuffered query and want to issue another query. You need to free the resources associated with the unused results. Alternatively, you must store any unbuffered results before issuing further queries. In all other circumstances, PHP automatically closes resources when the script ends.
closes resources when the script ends. Nevertheless, the recommended best practice is to close MySQLi resources as soon as they're no longer needed. With short example scripts such as in this course, it makes little or no difference. But on a busy website, freeing memory and handing back control to the MySQLi server could improve efficiency. It's also a good idea to free the memory associated with multiple result sets as soon as they're no longer required.
with multiple result sets as soon as they're no longer required.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 101596 Viewers
61 Video lessons · 88357 Viewers
71 Video lessons · 72203 Viewers
56 Video lessons · 103951 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.