I am getting data from MySQL and displaying in json format using php but my data are in Persian language and it show ? character instead of the original data
like given below.
{"allnews":[{"id":"35","Onvan":"???? ???? ????? ????? ?????? ?? ??? ?????"},{"id":"36","Onvan":"?????????? ???? ? ??????????? ?????"},{"id":"37","Onvan":" ??????? ???? ??? ??? ???? ???? ?? ??? ?? ???? ???? ??????? ??? ?????? ???????? ?? "},{"id":"38","Onvan":" ????? ????????? ???? ??? ?? ?? ??????? ????????"},{"id":"39","Onvan":"??? ???? ??? ????"}]}
Here is my code .Can you please check where has it gone wrong.
<?php
$hostname='localhost';
$username='xxxxxxxxx';
$password='xxxxxxxxx';
$response = array();
try {
$dbh=new PDO("mysql:host=$hostname;dbname=dbtest",$username ,$password);
$response["allnews"] = array();
/*** QUERY ****/
$sql='SELECT * FROM test';
$stmt=$dbh->query($sql);
$objs = $stmt->fetchAll(PDO::FETCH_OBJ);
foreach($objs as $object) {
$news = array();
$news["id"]=$object->id;
$news["Onvan"]=$object->title;
array_push($response["allnews"], $news);
}
echo json_encode($response);
/*** close connection ***/
$dbh=null;
}catch(PDOException $e) {
echo $e->getMessage();
}
?>