1. Go to this page and download the library: Download almhdy/json-shelter 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/ */
almhdy / json-shelter example snippets
// Include Composer's autoload file
se Almhdy\JsonShelter.JsonShelter;
// Create a new JsonShelter instance
$baseDir = "myDatabase"; // Base directory path
$secretKey = "your_secret_key"; // Your secret key
$secretIv = "your_secret_iv"; // Your secret IV
$logger = new Logger('json_shelter');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG));
$db = new JsonShelter($baseDir, $secretKey, $secretIv, $logger);
// Include the JsonShelter class file
Almhdy.JsonShelter.JsonShelter;
// Create a new JsonShelter instance
$baseDir = "myDatabase"; // Base directory path
$secretKey = "your_secret_key"; // Your secret key
$secretIv = "your_secret_iv"; // Your secret IV
$logger = new Logger('json_shelter');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::DEBUG));
$db = new JsonShelter($baseDir, $secretKey, $secretIv, $logger);
$db->enableEncryption();
$db->disableEncryption();
// Create a new record in 'myTable'
$db->create('myTable', ['name' => 'John', 'age' => 30]);
// Read a record from 'myTable' by ID
$record = $db->read('myTable', 1); // Replace 1 with the record ID
print_r($record); // Display the retrieved record
// Update a record in 'myTable' by ID
$db->update('myTable', 1, ['age' => 31]); // Increment age
// Delete a record from 'myTable' by ID
$db->delete('myTable', 1); // Replace 1 with the record ID
use Almhdy.JsonShelter.Model;
// Initialize a Model for the 'users' table
$userModel = new Model($db, 'users');
// Insert a new record
$userModel->create(['name' => 'Jane Doe', 'email' => '[email protected]']);
// Read all records
$users = $userModel->all();
print_r($users);
// Read a specific record by ID
$user = $userModel->find(1);
print_r($user);
// Update a record
$userModel->update(1, ['email' => '[email protected]']);
// Delete a record
$userModel->delete(1);
// Get users with the name 'Jane Doe'
$users = $userModel->where(['name' => 'Jane Doe']);
print_r($users);
// Search for users with 'example.com' in their email
$users = $userModel->search('email', 'example.com');
print_r($users);
// Order users by name in ascending order
$orderedUsers = $userModel->orderBy('name', 'asc');
print_r($orderedUsers);
// Limit the number of users returned
$limitedUsers = $userModel->limit(10, 0);
print_r($limitedUsers);
use Almhdy.JsonShelter.JsonEncryptor;
// Initialize JsonEncryptor
$encryptor = new JsonEncryptor('your_secret_key', 'your_secret_iv');