When using mysql_query inside of a class method and setting it to a local variable is memory freed when the method finishes execution or at the end of the script? Is it worth adding mysql_free_result? Below is example.
class example{
public function Query($query){
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$this->rows[] =$row;
}
}
}
Will memory be freed when the method finishes or is it necessary to call mysql_free_result at the end of the method?
First of all,
mysql_php functions are not maintained anymore and thus you may want to use a moreOOPapproach such as mysqli or PDO functions.Since
mysql_free_result()If you are fetching a lot of results then yes, you can (and should) use this function to free your mysql to save memory.
As for the rest of your question:
No, in case of you are not using the
mysql_free_resultthe memory won’t be freed at the end of your method but rather in the end of the execution of your script.I hope it helped. Cheers.