What are some potential pitfalls to avoid when working with PHP database connections?

One potential pitfall to avoid when working with PHP database connections is not properly closing the connection after it is no longer needed. Failing to close connections can lead to resource leaks and potential performance issues. To avoid this, always remember to close the database connection once you are done using it.

// Establish a database connection
$connection = mysqli_connect($servername, $username, $password, $dbname);

// Use the connection for database operations

// Close the connection when done
mysqli_close($connection);