How can PHP developers optimize their code structure by centralizing database connection scripts and including them in multiple pages to avoid repetitive code and potential errors?

To optimize code structure and avoid repetitive database connection scripts in PHP, developers can centralize the database connection script in a separate file and include it in multiple pages using PHP's include or require functions. This approach helps in reducing code duplication, improving maintainability, and reducing the chances of errors in database connection setup.

// db_connection.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "your_database";

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

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
```

To include the database connection script in other PHP files:

```php
// other_file.php
<?php
require_once('db_connection.php');

// Use $conn variable to interact with the database