2
I need to close the connection to the Mysql database in PHP in the code below:
try {
$conn = new PDO('mysql:host=localhost;dbname=banco', "root", "", array(PDO::ATTR_PERSISTENT => true));
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
//tenta fechar a conexao
$conn = null;
I need to close the persistent connection to a Mysql database in PHP. I tried to close the connection by setting the variable $conn
as null
, but it doesn’t seem to be working.
When I use the command SHOW STATUS WHERE
variable_name = 'Threads_connected';
in Mysql to check the active connections they do not decrease, but work when the connection is not persistent and Seto the variable $conn
as null
.
Someone could help me?
$conn = null;
this is correct, but a persistent connection as well as pools do not close immediately when destroys the object, if you want the connection closing when destroying the object do not use a persistent connection– Ricardo Pontual