如何通过json_encode从mySQL数据库加载数据?

时间:2017-09-01 01:53:40

标签: php mysql json

我正在通过json从我的数据库加载数据。

$data = $db->query('SELECT * FROM data ORDER BY id ASC;')->fetchAll(PDO::FETCH_ASSOC);
$json_string = json_encode($data);
$file = 'data.json';
file_put_contents($file, $json_string);

这意味着,当我从数据库加载数据时,我的文件data.json会更新。

data.json看起来像这样:

[{"id":"40","name":"Monkey","firstname":"Fred","company":"monkeys","street":"monkeystreet 23","plz":"11111","place":"Wonderland","email":"monkey@monkeyland.com","phone":"1111","fax":"1111","cell":"1111,"country":"Monkeyland","url":"","category":""}

这在我的localhost上运行得很好,但在我的服务器上,文件没有更新。 这意味着,如果我改变了,"猴子"进入" Bird",在我的数据库中它是" Bird"但是在json文件中它仍然是" Monkey"。

什么可能导致这个问题?我很高兴有任何帮助!

0 个答案:

没有答案