I am creating a PHP form, which collects items for a dropdown list from WordPress MySQL database. The database locale is set to utf8mb4_unicode_520_ci and I tried to force this in the code, however, my dropdown list still does not display any Cyrillic characters.
<div>
<label for="course_name">Course Name:</label>
<select id="course_name" name="course_name" required>
<?php
// Connect to the MySQL database
mysqli_set_charset($conn, "utf8mb4_unicode_520_ci");
mysqli_query($conn, "SET collation_connection = 'utf8mb4_unicode_520_ci'");
$conn = mysqli_connect("host", "user", "password", "database");
// Query to select all course names
$query = "SELECT post_title FROM wpv1_posts WHERE post_type = 'courses'";
$result = mysqli_query($conn, $query);
// Loop through the result set and create options for the dropdown list
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value='".$row['post_title']."'>".$row['post_title']."</option>";
}
mysqli_close($conn);
?>
</select>
</div>
The result in the dropdown at the moment is basically:
| Dropdown options |
|---|
| ?????? 12345678 |
| ?????? ???? ????? Text |
| Any English Text |
I tried forcing the locale through mysqli_set_charset($conn, "utf8mb4_unicode_520_ci"); and mysqli_query($conn, "SET collation_connection = 'utf8mb4_unicode_520_ci'");, as well as doing the same with cp1251_general_cs. This yielded no results.