PDO Connection Closure: Is it as Easy as Setting to NULL?
In comparison to MySQLi, where connection closure involves calling a specific function like close(), the PDO approach appears simpler. It suggests that assigning null to the connection object will effectively close the connection.
This approach is indeed correct. According to the PDO documentation, the connection remains active for the lifetime of the PDO object. To close the connection, it is necessary to destroy the object by assigning null to the variable holding it. If this is not explicitly performed, PHP will automatically close the connection when the script ends.
However, it's worth noting that this automatic closure does not apply to persistent connections. If a PDO object is initialized as a persistent connection, it will remain active until manually terminated.
The above is the detailed content of How do you Close a PDO Connection: Is Setting it to NULL Enough?. For more information, please follow other related articles on the PHP Chinese website!