0

What I am trying to achieve is to simply put all the rows of a mysqli result to a JSON file.

My code looks like this:

$sth = mysqli_query($mysqli, "SELECT * FROM table");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
    $rows[] = $r;
}
print_r($rows);
$mysqli->close();
$fileobj = fopen("takeOutItems.json", 'w');
fwrite($fileobj,json_encode($rows));
fclose($fileobj);

printing the $rows arrays shows data correctly. fwrite, however, does not change anything in takeOutItems.json.

What am I doing wrong?

nebulator0
  • 85
  • 8

1 Answers1

2

The issue was that some data elements were not displayed correctly. Adding $mysqli->set_charset("utf8"); resolved the issue.

nebulator0
  • 85
  • 8