PHP code example of irfan-dahir / folderdb
1. Go to this page and download the library: Download irfan-dahir/folderdb 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/ */
irfan-dahir / folderdb example snippets
$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'];
// 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