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

Use $link = null to let PDO know it can close the connection.

PHP: PDO Connections & Connection Management

Upon successful connection to the database, an instance of the PDO class is returned to your script. The connection remains active for the lifetime of that PDO object. To close the connection, you need to destroy the object by ensuring that all remaining references to it are deleted–you do this by assigning NULL to the variable that holds the object. If you don’t do this explicitly, PHP will automatically close the connection when your script ends.

Leave a Comment