PHP code example of ronolo / json-database

1. Go to this page and download the library: Download ronolo/json-database library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ronolo / json-database example snippets


$config = Database\Config();
$config->addStore('person', (new Store\Config())->setAdapter(new MemoryAdapter()));
$config->addStore('interests', (new Store\Config())->setAdapter(new MemoryAdapter()));

$database = Database::create($config);

$config = Database\Config();

$config->addStore('person', (new Store\Config())->setAdapter(new Local('/foo/bar/persons')));
$config->addStore('interests', (new Store\Config())->setAdapter(new Local('/foo/bar/interests')));
$database = Database::create($config);

// Create a few interests
$hobby1 = $database->put('interests', ['name' => 'Music', 'stars' => 4], true);
$hobby2 = $database->put('interests', ['name' => 'Boxen', 'stars' => 3.4], true);
$hobby3 = $database->put('interests', ['name' => 'Movies', 'stars' => 5], true);

// Create some persons
$person1 = $database->put('person', [
    'name' => 'Ronald',   
    'interests' => [$hobby1, $hobby2]
]);
$person2 = $database->put('person', [
    'name' => 'Ellen',   
    'interests' => [$hobby2, $hobby3]
]);
$person3 = $database->put('person', [
    'name' => 'James',   
    'interests' => []
]);
$person4 = $database->put('person', [
    'name' => 'Katja',   
    'interests' => [$hobby3, $hobby1, $hobby2]
]);

// Request of Katja which will return a JSON object with her 3 hobbies dereferenced.
$katja = $database->read('person', $person4);