What are the best practices for managing database connections in PHP applications using Xampp?

When managing database connections in PHP applications using Xampp, it is important to establish a single database connection that can be reused throughout the application to improve performance and reduce resource usage. One common approach is to create a separate PHP file that contains the database connection code and include this file in other PHP scripts where database operations are needed.

<?php
// Create a separate PHP file to establish a database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mydatabase";

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

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

In your other PHP scripts, you can include this database connection file at the beginning of the script to reuse the established connection.

```php
<?php
// Include the database connection file
include 'db_connection.php';

// Perform database operations using the $conn variable
$sql = "SELECT * FROM users";
$result = $conn->query($sql);

// Close the connection at the end of the script
$conn->close();