0

Here is the Data in my MySQL DB enter image description here

And the corresponding PHP code to retrieve it

$query = "SELECT * FROM `states` ORDER BY `NAME`";
$result = mysqli_query($connection, $query);

$json_response = array();

while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
    $field_info = mysqli_fetch_fields($result);
    foreach ($field_info as $value) {
        $row_array[$value->name] = $row[$value->name];
    }
    array_push($json_response, $row_array);
}
echo json_encode($json_response, JSON_UNESCAPED_UNICODE);

JSON output is printing ???? instead of actual text

Help ! Here is JSON Output JSON Output

Shadab Mehdi
  • 604
  • 10
  • 23
  • 1
    What is your database encoding? This is probably an encoding mismatch. You might want to try converting it to UTF-8 before the `json_encode`. – SamV Apr 05 '15 at 11:32
  • I tried, no luck.... – Shadab Mehdi Apr 05 '15 at 12:50
  • Have you tried without `JSON_UNESCAPED_UNICODE`? – SamV Apr 05 '15 at 12:59
  • Modified this `echo json_encode(utf8_encode($json_response));` `` `Warning: utf8_encode() expects parameter 1 to be string, array given ` – Shadab Mehdi Apr 05 '15 at 13:13
  • As with virtually every question of this type: **database connection encoding!** See the duplicate. If that doesn't help, update your question addressing this issue. – deceze Apr 23 '15 at 11:38
  • Hey @deceze, thanks for your reply, that was very informative, however i tried to follow the said procedure, added `mysqli_set_charset($connection, 'utf8mb4');` but no change. [Here](http://imgur.com/H5kjJpJ) is my DB. – Shadab Mehdi Apr 25 '15 at 07:55

0 Answers0