Reading Arabic text from mysql via json gives ? ?

Hi all,

I am trying to pull data from remote sql DB into lua table using php file to convert into json. I am using

[lua]

print json_encode($rows);

[/lua]

 

The issue that Arabic characters appear as ??? ??? . Any one has an idea how can I read Arabic language using properly

[lua]

<?php

 $username = “*****”;
 $password = “**********”;
 $dbname = “*************_db”;
 $hostname = “*.**********.com”;

 $qry = “select * from Events”;

 mysql_connect ($hostname, $username, $password) OR DIE (“Unable to connect to database! Please try again later.”);
 mysql_select_db($dbname) OR DIE (“Can not connect to database”) ;

 $result = mysql_query($qry);

 if ($result != FALSE && mysql_num_rows($result) > 0) {

 $rows = array();

 while($r = mysql_fetch_assoc($result)) {
 $rows[] = $r;
 }
 print json_encode($rows);
}
 else {
 print “Error: No records returned.”;
 }

 ?>

[/lua]

Thanks

Abdul

any help in this topic team . 

thx 

Abdul

Make sure everything is set to UTF8, the db, the client inserting the data, the page serving the data.

This is a Corona forum so your best bet is to Google it and then you get results like this: http://forums.mysql.com/read.php?103,209072,209072

Thanks jon for the advice, 

i searched a lot in google… i was able to put the character in arabic in MySQL with UTF8… the issue i am facing when i print it with json or when I echo the text just to see how it looks. In that case i got ??? ??? …  so it when i read it via corona , i got also  ??? ??? 

Did you try to do like that link suggests? Putting this in your php script (before doing your select):

[lua]mysql_query(“SET NAMES ‘utf8’”); 

mysql_query(‘SET CHARACTER SET utf8’); 

[/lua]

yes sir…

i did that but still no luck 

[lua]

mysql_query(“SET NAMES ‘utf8’”); 

mysql_query(‘SET CHARACTER SET utf8’); 

 $qry = “select * from Events”;

[/lua]

I was able to read the arabic character via corona when I changed the collation to for MYSQL table, row and sql to  

utf8_unicode_ci

and the follwoing lines in the php file 

<meta http-equiv=“Content-Type”

    content=“text/html; charset=utf-8” />

and this line before the select statement :

mysql_query(“SET NAMES ‘utf8’”); 

although the character was not showing properly in the json output but corona was able to accept that encoding … 

Regards

Adulaziz

Very good, these encoding problems can be very time consuming :slight_smile:

oh yeah,. spent few hours in that, thanks for helping in the issue :slight_smile:

regards

Abdul

Thanks for sharing your solution. Most appreciated.

any help in this topic team . 

thx 

Abdul

Make sure everything is set to UTF8, the db, the client inserting the data, the page serving the data.

This is a Corona forum so your best bet is to Google it and then you get results like this: http://forums.mysql.com/read.php?103,209072,209072

Thanks jon for the advice, 

i searched a lot in google… i was able to put the character in arabic in MySQL with UTF8… the issue i am facing when i print it with json or when I echo the text just to see how it looks. In that case i got ??? ??? …  so it when i read it via corona , i got also  ??? ??? 

Did you try to do like that link suggests? Putting this in your php script (before doing your select):

[lua]mysql_query(“SET NAMES ‘utf8’”); 

mysql_query(‘SET CHARACTER SET utf8’); 

[/lua]

yes sir…

i did that but still no luck 

[lua]

mysql_query(“SET NAMES ‘utf8’”); 

mysql_query(‘SET CHARACTER SET utf8’); 

 $qry = “select * from Events”;

[/lua]

I was able to read the arabic character via corona when I changed the collation to for MYSQL table, row and sql to  

utf8_unicode_ci

and the follwoing lines in the php file 

<meta http-equiv=“Content-Type”

    content=“text/html; charset=utf-8” />

and this line before the select statement :

mysql_query(“SET NAMES ‘utf8’”); 

although the character was not showing properly in the json output but corona was able to accept that encoding … 

Regards

Adulaziz

Very good, these encoding problems can be very time consuming :slight_smile:

oh yeah,. spent few hours in that, thanks for helping in the issue :slight_smile:

regards

Abdul

Thanks for sharing your solution. Most appreciated.