I am new to php and I am trying to create an API service out of it. I have saved the data in Nepali language in the database but when trying to print the json using json_decoded it returns "???????" characters.
This is what is stored in db:
This is what is printed:
and this is my code:
header('Content-Type: application/json; charset=utf-8');
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM example";
$sth = mysqli_query($conn, $sql);
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
$conn->close();
So whats the error here? My database collaction is "utf8_general_ci".