What are the consequences of not closing the database connection explicitly in PHP scripts, and what is the recommended approach for handling database connections?
Not closing the database connection explicitly in PHP scripts can lead to resource leaks and potential performance issues. It is recommended to always close the database connection after using it to free up resources and prevent any potential issues with the database server.
// Open a connection to the database
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
// Perform database operations here
// Close the database connection
mysqli_close($conn);