What are the potential security risks of storing usernames and passwords in a PHP script like config.php?

Storing usernames and passwords directly in a PHP script like config.php poses a security risk because if the file is accessible to unauthorized users, they can easily view and misuse the credentials. To mitigate this risk, it is recommended to store sensitive information like usernames and passwords in a separate configuration file outside of the web root directory. This way, even if someone gains access to the PHP files, they won't be able to directly access the sensitive information.

<?php
// config.php
define('DB_HOST', 'localhost');
define('DB_USERNAME', 'your_username');
define('DB_PASSWORD', 'your_password');
define('DB_NAME', 'your_database');