Prepared statements: consequences of the absence of free_result () or close ()

0

In the matter of prepared sentences that problems would generate the absence of the following two functions:

close() and free_result()

Try the following two cases and nothing negative happens:

Close the statement : $statement->close(); I was testing and if several statements are used without using close(); for over it seems that it does not give an error.

Release results , after a while or for : Using while and for to generate lists of data, fill checkbox and others and avoid placing the function free_result () and not seen problems.

However, I ask my question: There is a problem if I do not use close() and free_result()

    
asked by Victor Alvarado 06.04.2017 в 16:31
source

2 answers

1

I'll tell you what the PHP Manual says in both cases. The bold letters are mine, and they are intentional:)

close ()

  

Non-persistent MySQL connections and result sets   are automatically destroyed when a PHP script completes its   execution. Therefore, although the explicit closure of connections   open and the release of result sets are optional,   It is recommended to do them. Thus, resources will be immediately returned   to PHP and MySQL, which can improve performance. To   Detailed information, see the resource release .

free_result ()

  

The result should always be released with mysqli_free_result() , when the result object is no longer needed.

Conclusion

close() ? - > always

free_result() ? - > always

What if I do not want to do it ?, maybe nothing apparently , but your program will not be optimized from the point of view of performance and you could have errors of type MEMORY EXHAUST u other. So, in the case of MySQLi, better close what you open ... PDO is another story.

Links:
answered by 06.04.2017 / 17:32
source
1
  

Non-persistent MySQL connections and result sets   are automatically destroyed when a PHP script completes its   execution. Therefore, although the explicit closure of connections   open and the release of result sets are optional,   It is recommended to do them. Thus, resources will be immediately returned   to PHP and MySQL, which can improve performance.

mysqli_close ();

  

You should always release the result with mysqli_free_result (), when   the object of the result is no longer necessary.

mysqli_free_result ();

The reality is that as indicated by the PHP documentation, it is optional, nothing happens, but believe me that when the queries are already at production level and not local tests, the life of the server memory is vital for the company.

That it serves you, greetings.

    
answered by 06.04.2017 в 17:34