Reputation: 41
i am using json output for my application and stored all data in my native language in mysql
server with utf8_general_ci
when i am fetching that using json_encode i got the json array but the data format is not supported in that. how can i solve it.
code which i used to create json data.
<?php
header('Content-type: text/html; charset=utf-8; pageEncoding="ISO-8859-1"');
include('include/config.php');
mysql_query("SET NAMES 'utf-8' 'ISO-8859-1'");
//mysql_query("SET CHARACTER SET utf8 ISO-8859-1");
$sth = mysql_query("select v.verse,b.book_name,v.chapter,v.verse_number from tbl_verses_mal v inner join tbl_books_mal b on v.book_id=b.book_id");
$rows = array();
while($r = mysql_fetch_assoc($sth)) {
$rows[] = $r;
}
print json_encode($rows);
?>
the output i got is like
[{"verse":"???????? ?????? ???????? ?????? ??? ????????? . ?? ????????? ??? ??????? ????????????????? .","book_name":"Genesis","chapter":"1","verse_number":"1"},{"verse":"???? ??????? ?????????? ??????? : ???????????? ???? ????????????? .????????????? ??????? ??????","book_name":"Genesis","chapter":"1","verse_number":"2"},{"verse":"???????? ?????????? ????? ???? ?????????: ???????? ??????? ","book_name":"Genesis","chapter":"1","verse_number":"3"}]
?????
marks represents the language which is in the database.
the expected results is like given below
[{"verse":"അയൽകാരന് ആവശ്യം വരുമ്പോൾ നിങ്ങൾ കടം കൊടുക്കു. .","book_name":"Genesis","chapter":"1","verse_number":"1"},{"verse":"ഭൂമി പാഴായും ശൂന്യമായും ഇരുന്നു : ആഴത്തിന്മീതെ","book_name":"Genesis","chapter":"1","verse_number":"2"},]
how can i solve this issue??
Upvotes: 0
Views: 225
Reputation: 194
you need to set character set properly try like
mysql_set_charset('utf8');
And mysql_*
function are deprecated use PDO
or Mysqli
instead
Upvotes: 0
Reputation: 522075
mysql_query("SET NAMES 'utf-8' 'ISO-8859-1'");
This makes no sense. Set the charset properly:
mysql_set_charset('utf8');
Upvotes: 1