What are best practices for configuring database connection settings in PHP scripts for local development environments like XAMPP?

When configuring database connection settings in PHP scripts for local development environments like XAMPP, it is best practice to store sensitive information such as database credentials in a separate configuration file outside of the web root directory. This helps to prevent unauthorized access to the database information. Additionally, using constants to define the database connection settings can make it easier to update the credentials in one central location.

<?php
// Define database connection settings
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'database_name');

// Create a database connection
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

// Check the connection
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}