What are some best practices for populating a dropdown list with values from a MariaDB database in PHP?

When populating a dropdown list with values from a MariaDB database in PHP, it is important to establish a database connection, query the database for the desired values, fetch the results, and then loop through the results to populate the dropdown list options.

<?php
// Establish a connection to the MariaDB database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

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

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

// Query the database for the desired values
$sql = "SELECT value_column FROM table_name";
$result = $conn->query($sql);

// Populate the dropdown list with the fetched values
echo '<select name="dropdown">';
while($row = $result->fetch_assoc()) {
    echo '<option value="' . $row['value_column'] . '">' . $row['value_column'] . '</option>';
}
echo '</select>';

// Close the database connection
$conn->close();
?>