0

Can someone explain me how does PHP interacts with MySQL. I want to know when I make queries using mysql_query when the connection is closed. Or should I use mysql_close()...

I thought that the connection is open while the page is being interpret and closes when it's done with interpreting.

Ivanka Todorova
  • 9,964
  • 16
  • 66
  • 103
  • ... closing it manually seems to be a good practice to follow: [enter link description here][1] [1]: http://stackoverflow.com/questions/880885/close-mysql-connection-important – vector Feb 28 '12 at 19:10

3 Answers3

3

The connection remains open from the mysql_connect call until either:

  • mysql_close is called
  • the reference to the connection ($db = mysql_connect...) is unset (with unset, or falls out of scope)
  • the script finishes executing
Joe
  • 15,669
  • 4
  • 48
  • 83
2

http://php.net/manual/en/function.mysql-close.php

You don't need to close explicitly.

rob
  • 266
  • 3
  • 3
0

Use mysql_close() only if you are concerned about size of the transfer. If it is not huge, you are OK without it.

Mark Ursino
  • 31,209
  • 11
  • 51
  • 83
Whitewall
  • 597
  • 1
  • 7
  • 18