PHP code example of sinevia / php-library-jsondb

1. Go to this page and download the library: Download sinevia/php-library-jsondb 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/ */

    

sinevia / php-library-jsondb example snippets


// Initializing database, creating file if not existing
$db = new JsonDb('yourdb.json', true);

// Setting keys
$db->set('key1', 'Value of Key 1');
$db->set('key2', 'Value of Key 2');
$db->set('key3', 'Value of Key 3');

// Saving to database
$db->save();

// Getting keys
$key1 = $db->get('key1');
$key2 = $db->get('key2');
$key3 = $db->get('key3');

// Removing keys
$db->remove('key1');
$db->remove('key2');
$db->remove('key3');
$db->save();

// Deleting database
$db->delete();

// Check if database exists
if($db->exists()){
    echo 'Database ' . $db->filePath . ' exists';
} else {
    echo 'Database ' . $db->filePath . ' DOES NOT exist';
}


composer