0

Hello I have 2 query in one file (I have mysqli database class)

1 query is in if else

2 second query is not in if else

my question is where I must to close mysql?

<?php db::mysqli()->close(); ?>
Gocha
  • 169
  • 1
  • 2
  • 13
  • 2
    Either when you're done with all of your queries, or not at all. The connection will close automatically when the script is done. – aynber Dec 30 '16 at 13:29
  • so I must close mysql end of my file? – Gocha Dec 30 '16 at 13:29
  • 3
    You don't have to, since it will close on its own, but you can to free up some resources. – aynber Dec 30 '16 at 13:30
  • okey, but I do not understand, whay need mysqli close function if it closes automatic – Gocha Dec 30 '16 at 13:32
  • 2
    Open non-persistent MySQL connections and result sets are automatically destroyed when a PHP script finishes its execution. So, while explicitly closing open connections and freeing result sets is optional, doing so is recommended. This will immediately return resources to PHP and MySQL, which can improve performance. For related information, see freeing resources. [src](http://php.net/manual/en/mysqli.close.php) – aynber Dec 30 '16 at 13:33
  • 1
    Gocha in case of real long scripts, where you want to free the resources ash a@aynber said. But considering most applications and today's computing capabilities...closing is not needed at all. – sidyll Dec 30 '16 at 13:33
  • 1
    To enable a programmer to close a connection at will. – Shadow Dec 30 '16 at 13:34
  • Thanks now I am understand. – Gocha Dec 30 '16 at 13:35
  • 3
    (1): [Is closing the mysql connection important?](http://stackoverflow.com/questions/880885/) (2): [Do I really need to do mysql_close()](http://stackoverflow.com/questions/3359716/) (3): [When should I close a database connection in PHP?](http://stackoverflow.com/questions/20492427/) – sidyll Dec 30 '16 at 13:36

0 Answers0