What are the benefits of using a separate file for database connection details in PHP scripts, and how does it enhance code organization?

By using a separate file for database connection details in PHP scripts, you can enhance security by keeping sensitive information like database credentials separate from the main code. This also makes it easier to update connection details in one central location without having to search through all your scripts. Additionally, it improves code organization by separating database configuration from the rest of the application logic.

// db_config.php
<?php
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "my_database";
```

```php
// index.php
<?php
include 'db_config.php';

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";