Are there any potential security risks associated with storing login credentials in PHP scripts?

Storing login credentials in PHP scripts can pose a security risk as the credentials are easily accessible to anyone who has access to the code. To mitigate this risk, it is recommended to store the credentials in a separate configuration file outside of the web root directory. This way, even if someone gains access to the PHP scripts, they won't be able to directly view the login credentials.

<?php
// config.php
define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database_name');
?>