2

I have a simple mysql database table and php script.

With my php script i get data from DB and write it into an array.

<?php
header('Content-Type: application/json; charset=utf-8');
include "db.php";

$data=array();
$query=mysqli_query($con,"select * from table");
while ($row=mysqli_fetch_object($query)){
 $data[]=$row;
}

echo json_encode($data);
?>

If there are no German Umlaute, like "ä" or "ü" in my DB, the JSON string works fine.

Example:

[{"id":"1","kopfzeile":Test,"titel":"Test","beschreibung":"Test"}]

But if there are German Umlaute, like "ä" or "ü", in my DB, i get the value NULL in my JSON string

[{"id":"1","kopfzeile":null,"titel":"null","beschreibung":"null"}]

I want a JSON like this:

[{"id":"1","kopfzeile":Über,"titel":"Hallü","beschreibung":"ÖÜÄ"}]

How to fix this issue?

fcb1900
  • 339
  • 4
  • 21
  • 3
    Probably a character-encoding issue. It's important to ensure that everything is UTF8. Your database and all its tables, your PHP script, the connection between the PHP script and the database, the form input, everything. If anything isn't you'll risk tripping issues like this. – GordonM Apr 14 '17 at 17:40
  • First of all, your JSON examples are all invalid. – jchook Apr 14 '17 at 17:42
  • 1
    In db.php: **mysqli_set_charset($link, "utf8");** : http://stackoverflow.com/questions/4076988/php-json-encode-json-decode-utf-8 – Hossam Apr 14 '17 at 17:43
  • I use the following character encoding config options for mysql: https://pastebin.com/raw/ipuWeJ2w – jchook Apr 14 '17 at 18:13

0 Answers0