1

I am trying to fetch arabic data from mysql database collation utf8_general_ci but while inserting data in database worked fine.When i tried to fetch data it gave me some different symbols.

//*$response = array(); 

$username = "root";
$password = "";
$hostname = "localhost"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");



//select a database to work with
$selected = mysql_select_db("tellmedb",$dbhandle) 
 or die("Could not select tellmedb");


//execute the SQL query and return records
mysql_query("SET NAMES utf8");
mysql_query("set characer set utf8");
$result = mysql_query("SELECT * FROM tbl_restaurantara") or die(mysql_error()); 


// Check whether there is data(record more than 0) 
if (mysql_num_rows($result) > 0) 
{ 

 // looping result mysql_query 
 $response["list_rs"] = array(); 

 while ($row = mysql_fetch_array($result)) 
 { 

 // temp user array 
 $list_rs = array(); 
 $list_rs["id_rs"] = $row["id"]; 
 $list_rs["name_rs"] = stripslashes($row["name"]); 
 $list_rs["link_image_rs"] = 
 stripslashes($row["link_image"]);
 $list_rs["url1_rs"] = 
 stripslashes($row["url1"]);
 $list_rs["url2_rs"] = 
 stripslashes($row["url2"]);
 $list_rs["url3_rs"] = 
 stripslashes($row["url3"]); 
 $list_rs["address_rs"] = 
 stripslashes($row["address"]); 
 $list_rs["telepon_rs"] = 
 stripslashes($row["phone"]); 
 $list_rs["booking_rs"] = 
 stripslashes($row["bookingurl"]);
 $list_rs["offer_rs"] = 
 stripslashes($row["offersurl"]);
 $list_rs["location_rs"] = 
 stripslashes($row["location"]);

// display the query results in the form of an array
  array_push($response["list_rs"], $list_rs); 
 } 

 // success 
 $response["success"] = 1; 

 // echoing JSON response 
 echo json_encode($response,JSON_UNESCAPED_UNICODE); 
 } 
 else { 

 // No data 
 $response["success"] = 0; 
 $response["message"] = "No DATA"; 

 // echoing JSON response 
 echo json_encode($response,JSON_UNESCAPED_UNICODE); 
} 

//close the connection
mysql_close($dbhandle); */

output is below:

/*وعب، أسباير زوÙ*/

2 Answers2

0

First of all please confirm that the arabic text is saving correctly in the database, if it is ok then just try after removing this line from your code

mysql_query("set characer set utf8");

and add

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

this code

and if arabic text is not correctly saved in database then please change your database collation to UTF-8.

Shani
  • 142
  • 2
  • 9
0

Try this:

// connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");

mysql_set_charset('utf8', $dbhandle);

Also remove this line:

mysql_query("set characer set utf8");

See discussion here

groverboy
  • 1,133
  • 8
  • 20