FolderDB is a flat-file JSON database with usage similarity to MongoDB's PHP API.
It saves data into directories as files with key/value pairs in JSON format. The "key" is the file name where the "value" is JSON data.
FolderDB uses magic methods to automatically create or manage "collections"/directories.
composer require irfan-dahir/folderdb
$client->users->insert(
'username',
\FolderDb\Document::fromArray([
'id' => '123',
'first_name' => 'John',
'last_name' => 'Doe',
'email' => '[email protected]'
])
);
$user = $client->users->get('username');
echo $user->email; // "[email protected]"
// To Array
echo $user->toArray()['email'];
require_once __DIR__ .'/vendor/autoload.php';
// Create a client and pass the path to the database folder
$client = new \FolderDb\Client('/path/to/database');
$client->users;
$data = [
'id' => '123',
'first_name' => 'John',
'last_name' => 'Doe',
'email' => '[email protected]'
];
// `new \FolderDb\Document()` takes JSON string directly, so we have to convert it to array
$client->users->insert(
'username',
\FolderDb\Document::fromArray($data)
);
echo $client->users->count(); // 2
$user = $client->users->get('username'); // returns `\FolderDb\Document`
// Access your entry as an object
echo $user->email; // "[email protected]"
// Access your entry as an array
$userArray = $user->toArray();
echo $userArray['email']; // "[email protected]"
$user = $client->users->getAll(); // returns array of `\FolderDb\Document`
$client->users->exists('username'); // returns boolean
$user->delete(); // returns boolean
- PHP 7.1+
- irfan-dahir/php-mom
Please create an issue for any bugs/security risks/etc