What are the potential risks of directly embedding PHP code for database queries in HTML files?

Embedding PHP code for database queries directly in HTML files can pose security risks such as SQL injection attacks and exposing sensitive information. To mitigate these risks, it is recommended to separate the PHP logic from the presentation layer by using a template engine or MVC framework.

```php
// Example of separating PHP logic from presentation layer using a simple template engine

<?php
// Database connection and query execution
$connection = mysqli_connect('localhost', 'username', 'password', 'database');
$query = "SELECT * FROM users";
$result = mysqli_query($connection, $query);

// Fetching data and passing it to the template
$users = [];
while ($row = mysqli_fetch_assoc($result)) {
    $users[] = $row;
}

// Include the HTML template file
include 'template.php';
?>
```

In the `template.php` file, you can then use PHP to iterate over the `$users` array and display the data in the HTML markup. This approach helps to keep the database queries separate from the presentation layer, reducing the risk of security vulnerabilities.