Problem turning collected data into a json file

Asked

Viewed 26 times

0

I am trying to write in a file . json, information I collect from a database but for some reason nothing is written.

Follow the code:

require_once('../helpers/connect.php');
require_once('../models/marks.php');

$marks = Mark::select($pdo);

$rows = array();

if (isset($marks)) {
    foreach ($marks as $row) {
        $rows[] = array('id' => $row['id'], 'titulo' => $row['titulo'], 'descricao' => $row['decricao'], 'latitude' => $row['latitude'], 'longitude' => $row['longitude']);

    }
}

$file = fopen('c:/xampp/htdocs/hemoba/assets/js/marks.json', 'w+');
fwrite($file, json_encode($rows));
fclose($file);
?>

  • Makes a mistake?.

  • Hello Miguel, no

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.