What are the best practices for securely storing and accessing database credentials in PHP applications, considering the potential risks of storing passwords on the server?

Storing database credentials securely in PHP applications is crucial to prevent unauthorized access to sensitive information. One common best practice is to store credentials in a separate configuration file outside of the document root and restrict access to it. Additionally, using environment variables or encryption techniques can further enhance security.

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

```php
// db_connection.php
require_once 'config.php';

$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);

if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
}