Do SQL connections opened with PDO in PHP have to be closed -


When I open a MySQL connection in PHP in the underlying MySQL functions of PHP, I do the following:

$ link = mysql_connect ($ server name, $ user name, $ password); Mysql_select_db ($ dbname); // queries etc. mysql_close ($ link);

When I open a connection with the PDO, it looks like:

  $ link = new PDO ("mysql: dbname = $ dbname; Host = $ server ", $ username, $ password); // Ready statement, execute the query  

Do I explicitly close the connection such as I mysql_connect () and mysql_close ()

TIA

Use $ link = null to detect PDOs , It can close the connection.

On a successful connection from the database, an example of PDO class is returned to your script which is active for the lifetime of that PDO object. To turn off the connection, you must destroy the object by making sure its remaining references have been removed - you specify this with the variable with the variable that holds the object. If you do not explicitly do this, then PHP will automatically close the connection when your script is finished.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -