我想使用存储过程创建一个JSON文件,并在我的表数据发生更改时更新jsonfile。我不知道该怎么做。请任何人帮我解决这个问题吗?
答案 0 :(得分:1)
<?php
$someNewData = array("foo"=>"bar"); //example
if(!file_exists("./data.json")) {
$file = fopen('data.json', 'w');
fwrite($file, '');
fclose($file);
}
$jsonData = json_decode(file_get_contents("./data.json"), true);
if(!is_array($jsonData)){$jsonData=array();}
if(isset($someNewData) && is_array($someNewData)){
file_put_contents("./data.json", json_encode(array_merge($someNewData, $jsonData)));
}
我希望能帮到你:)。