0

Hey so i'm getting text with latin characters like "ó" from a mysql database. This is the connection along with the query i'm using to get the data, placing it in an array:

<?php
    header('Content-Type: text/html; charset=UTF-8');
    $con=new mysqli ("localhost","root","","chroniclemark");

    $sqlget = "SELECT descricao FROM items;";
    $sqldata = mysqli_query($con,$sqlget) or die ('error getting database');
    while ($row = mysqli_fetch_array($sqldata, MYSQLI_ASSOC)) {
        $lol5[] = $row['descricao'] ;
     }?>

I'm then trying to display the the text outside of the <?php ?> statement like so:

<p ><?php echo $lol5[0]; ?></p>

All of the text is fine except for the "ç", "ó", "ã" and so on. I also have a meta tag <meta charset="UTF-8"> in my header but it doen't help. In the database, the data is set to "utf8mb4_unicode_ci". What can i do to fix this? Any idea?

1 Answers1

2

@Fred -ii Thanks for pointing me in the right direction in the comments. All i had to do was use mysqli_set_charset($con, 'utf8mb4'); before making the query

$sqlget = "SELECT descricao FROM items;";
 $sqldata = mysqli_query($con,$sqlget) or die ('error getting database');

It's all fine now :)