Are there potential security risks in storing connection strings in text files for PHP applications?

Storing connection strings in text files for PHP applications can pose security risks as the information can be easily accessed if the text file is not properly secured. To mitigate this risk, it is recommended to store sensitive information like connection strings in environment variables or use a configuration file outside of the web root directory.

// Example of storing connection string in environment variable
$servername = getenv('DB_SERVER');
$username = getenv('DB_USERNAME');
$password = getenv('DB_PASSWORD');
$database = getenv('DB_NAME');

// Example of using a configuration file outside of the web root directory
$config = parse_ini_file('/path/to/config.ini');
$servername = $config['DB_SERVER'];
$username = $config['DB_USERNAME'];
$password = $config['DB_PASSWORD'];
$database = $config['DB_NAME'];