What are the potential pitfalls of using external files to store database connection data in PHP?

Potential pitfalls of using external files to store database connection data in PHP include security risks such as exposing sensitive information if the file is not properly secured, difficulty in managing and updating connection details across multiple files, and potential performance issues if the file is accessed frequently. To mitigate these risks, it is recommended to store connection data in a secure location outside of the web root directory and restrict access to the file.

<?php
// database_config.php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database');

// index.php
include_once 'database_config.php';

$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

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