0

API link :: http://www.nobannoo.com/AppLandingPage/text.php

<?php
require_once 'dbconfig.php';
$query = "SELECT * FROM tc_cerealname";
$stmt = $DBcon->prepare($query);
$stmt->execute();
$userData = array();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
    $userData['All Cereal Name'][] = $row;  
}
echo json_encode($userData, JSON_UNESCAPED_UNICODE);
?>

Output :: "id": "1", "cereal_name_en": "Paddy", "cereal_name_bn": "???"

Desired Output :: "cereal_name_bn": "ধান"

Ashiqur Rahman
  • 425
  • 7
  • 21
  • perhaps this may help: https://stackoverflow.com/questions/23322312/php-json-encodestring-json-unescaped-unicode-not-escaping-czech-chars – akrys Dec 04 '16 at 10:44
  • doesn't help much – Ashiqur Rahman Dec 04 '16 at 10:57
  • What exactly doesn't help? The answer there suggests two things that are relevant here: 1.) It suggests to send the output as JSON, by adding `header('content-type: application/json;charset=utf-8');` (I just added a charset to be sure it's utf-8) 2.) It also suggests to make sure the database connection uses UTF-8 as well. It describes it for mysqli, but on php.net I found a comment which describes a possible solution for PDO: https://secure.php.net/manual/en/pdo.construct.php#113498 – akrys Dec 04 '16 at 11:30

1 Answers1

0

See 'question marks' in Trouble with utf8 characters; what I see is not what I stored

  • The bytes to be stored are not encoded as utf8/utf8mb4. Fix this.
  • The column in the database is CHARACTER SET utf8 (or utf8mb4). Fix this.
  • Also, check that the connection during reading is UTF-8.

Do you have

$DBCon->set_charset('utf8');

(or utf8mb4).

But, I suspect the data was not properly stored. See the notes in that link for doing SELECT col, HEX(col) FROM ....

Community
  • 1
  • 1
Rick James
  • 135,179
  • 13
  • 127
  • 222