I have a PHP website that includes a "functions.php" script, where a mySQL connection is created. The connection works fine; however I'm getting trouble closing (destroying) it. Even if I place it at the end of said script, the connection is destroyed before some other code is executed and therefore fails. A solution would be to add it to the end every file that includes this script, but I would want to avoid this.
Code:
static $mysqli ;
if(!isset($mysqli)) {
$mysqli = new mysqli([...credentials...]) ;
}
if($mysqli->connect_error) {
die("Falló la conexión a base de datos: " . $connection->connect_error) ;
}
Expected result: stable connection, no errors and destruction of connection.
Actual result: either connection is not closed or if closing is destroyed too early.
Can you help me sorting through this? Where should I place a $mysqli->close() line?
Thanks!