-1

I have imported 17 thousand lines of data into an SQL database via phpmyadmin running with Apache2 on Ubuntu Server 18.04.

When trying to display the data with PHP on my localhost website, UFT-8 symbols won't show properly.

I'm doing this:

$conn = mysqli_connect($servername, $username, $password, 'Drinks');
$sql = "SELECT * FROM drinks LIMIT 10";
$result = $conn->query($sql);

while($row = $result->fetch_assoc()) {
  echo "<tr><th>" . $row["Name"]. "</th></tr>";
}

My database table is set to utf8mb4_general_ci and all rows are imported with INSERT.

My website head in my index.php is set to <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"> and i've also tried <meta charset="UTF-8">.

All symbols ARE showing correctly in phpmyadmin. Why won't they show on my website?

Thank you!

Fredrik Burmester
  • 237
  • 1
  • 4
  • 9
  • Maybe because you said the charset was `ISO-8859-1` in your meta tag …? – 04FS Mar 26 '19 at 10:16
  • I've tried as well. Did not work. – Fredrik Burmester Mar 26 '19 at 10:18
  • Go through the linked duplicate, and check _all_ the relevant stuff. – 04FS Mar 26 '19 at 10:21
  • Thank you i did and i made it work! I did do alot of searching before posting here. Sadly i didn't find this link on my own: https://stackoverflow.com/questions/10367133/utf-8-showing-correctly-in-database-however-not-in-html-despite-utf-8-charset which helped me solve it. Thank you all! – Fredrik Burmester Mar 26 '19 at 10:23

1 Answers1

1

I did this to make it work:

$db->query('set character_set_client=utf8mb4');
$db->query('set character_set_connection=utf8mb4');
$db->query('set character_set_results=utf8mb4');
$db->query('set character_set_server=utf8mb4');

Thank you all.

Fredrik Burmester
  • 237
  • 1
  • 4
  • 9