-1

I'm trying to get cyrillic data from MySQL database using php I set utf-8

$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());

    mysql_query("SET character_set_client = utf8");
    mysql_query("SET character_set_connection = utf8");
    mysql_query("SET character_set_results = utf8");

And when i set cyrillic data in db it works properly, but when I'm trying to get it:

 $product["id"] = $row["id"];
    $product["first_name"] = $row["first_name"];
    $product["last_name"] = $row["last_name"];
    $product["vk_id"] = $row["vk_id"];
    $product["points"] = $row["points"];

    // push single product into final response array
    array_push($response["users"], $product);
 echo json_encode($response);

And it gives me \u0416\u0430\u043c\u0431\u044b\u043b

and when I change json_encode($response); to json_encode($response, JSON_UNESCAPED_UNICODE);

it gives me :ЖамбыР

How can I get readable cyrillic data?

Zhambul
  • 942
  • 9
  • 23

1 Answers1

1

First of all, stop using mysql extension instead use mysqli or pdo. MySQL is vulnerable to sql injections. For more info read this answer.
Secondly, if use mysqli_set_charset('utf8') or mysql_set_charset('uft8') to set seesion encoding to utf8in your vulnerable case.
Thirdly, check encoding and colation in your database field, most likely it has something like latin1, change it to utf8_general_ci. And lastly, i suspect that you are viewing results in browser? If this is the case then set headers in php likes this header('Content-Type: text/html; charset=utf-8');

Community
  • 1
  • 1
RuslanN
  • 398
  • 3
  • 18