What are the best practices for closing a MySQL connection in PHP code to avoid syntax errors?

When closing a MySQL connection in PHP code, it is important to ensure that the connection is properly closed to avoid syntax errors and potential memory leaks. The best practice is to use the `mysqli_close()` function to explicitly close the connection after executing all necessary queries and operations.

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

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

// Perform operations with the database

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