What are best practices for structuring PHP code, especially when dealing with large databases, to avoid parsing errors and improve performance?

When dealing with large databases in PHP, it is best practice to separate your code into different files for better organization and maintainability. This can help avoid parsing errors and improve performance by allowing you to easily locate and debug issues. Additionally, using functions and classes can help encapsulate and reuse code, reducing duplication and enhancing readability.

// database.php
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

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

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

```php
// query.php
<?php
include 'database.php';

$sql = "SELECT * FROM table";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();