What are the security implications of storing passwords in PHP code, and how can developers mitigate these risks?

Storing passwords directly in PHP code poses a security risk as the passwords can be easily accessed if the code is compromised. To mitigate this risk, developers should store passwords securely hashed in a separate configuration file outside of the web root directory.

<?php
// config.php
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'hashed_password_here');
define('DB_HOST', 'localhost');
define('DB_NAME', 'database_name');
?>