When working with MySQL databases in PHP, what considerations should be made regarding connection management and resource cleanup?

When working with MySQL databases in PHP, it is important to properly manage connections and clean up resources to avoid memory leaks and performance issues. This can be done by ensuring that connections are closed after they are no longer needed and that resources such as result sets are freed up when they are no longer in use.

// Establish a connection to the MySQL database
$mysqli = new mysqli("localhost", "username", "password", "database");

// Check for connection errors
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

// Perform database operations

// Close the connection when done
$mysqli->close();