How important is it to securely store database credentials in PHP scripts to prevent potential errors and security vulnerabilities?

It is crucial to securely store database credentials in PHP scripts to prevent potential errors and security vulnerabilities. Storing credentials in plain text within scripts can expose sensitive information to unauthorized access. To mitigate this risk, it is recommended to store credentials in a separate configuration file outside the web root directory and use PHP constants to access them securely.

<?php

define('DB_HOST', 'localhost');
define('DB_USER', 'username');
define('DB_PASS', 'password');
define('DB_NAME', 'database');

// Other database connection code
$connection = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

?>