What are common pitfalls when using mysql_close() in PHP and how can they be avoided?

Common pitfalls when using mysql_close() in PHP include closing the connection prematurely before all queries have been executed or trying to close a connection that has already been closed. To avoid these issues, it is recommended to only close the connection when it is no longer needed and to check if the connection is still open before attempting to close it.

// Check if the connection is still open before closing it
if ($connection) {
    mysql_close($connection);
}