12345678910111213141516 |
- <?php
- class JsonDatabase {
- public function read($filename) {
- $fileContents = file_get_contents(DATA_PATH . $filename);
- return json_decode($fileContents, true);
- }
- public function write($filename, $dataToMerge) {
- $originalData = $this->read($filename);
- $mergedData = array_merge($originalData, $dataToMerge);
- $fileHandle = fopen(DATA_PATH . $filename, "w");
- $fileText = json_encode($mergedData, true);
- fwrite($fileHandle, $fileText);
- fclose($fileHandle);
- }
- }
|