What are the potential drawbacks of not properly handling database connections in PHP code?

Improper handling of database connections in PHP code can lead to issues such as resource leaks, connection timeouts, and decreased performance. To avoid these problems, it is important to properly open and close database connections within your code to ensure that resources are released and connections are not left open unnecessarily.

// Correct way to handle database connections in PHP
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

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

// Perform database operations here

// Close connection
$conn->close();