What are the best practices for storing sensitive information, such as database credentials, in a PHP application?

Storing sensitive information, such as database credentials, securely in a PHP application is crucial to prevent unauthorized access. One common practice is to store these credentials in a separate configuration file outside of the web root directory and restrict access to it. Another approach is to use environment variables to store sensitive information and access them in your PHP code.

// config.php

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

```php
// index.php

require_once 'config.php';

$connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($connection->connect_error) {
    die("Connection failed: " . $connection->connect_error);
}