PHP code example of sevens / jsondb

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

    

sevens / jsondb example snippets


$data = [
   'name' => 'Random 1',
   'age' => 24, 'password' => 'gHAST_V43SS',
   'nickname' => 'dick & harry'
];

use Seven\JsonDB\JsonDB;

$db = JsonDB::init($directory, $database);

$table = JsonDB::init($directory, $database, $tblName);

//OR

$table = $db->setTable($tblName);


use Seven\JsonDB\JsonDB;

$newDB = JsonDB::make(string $directory, $database): string;
#returns database name if successfully created

$schema = [
	'name', 'email', 'password'
];
$table->createTable($table, $schema);

//To use the 'save' method, you need to use a schema when creating a table

use Seven\JsonDB\JsonDB;

$newDB = JsonDB::list(string $directory): array;
#returns an array of databases found

use Seven\JsonDB\JsonDB;

$newDB = JsonDB::count(string $directory): int;
#returns number of databases found

use Seven\JsonDB\JsonDB;

$newDB = JsonDB::delete($directory, $db): bool;
#returns true name if successfully deleted

use Seven\JsonDB\JsonDB;

$newDB = JsonDB::empty($directory, $db): void;
#returns database name if successfully created

use Seven\JsonDB\Table;

$table->generateId(Table::TYPE_STRING || Table::TYPE_INT);

//default is Table::TYPE_STRING

$table->lastInsertId();

//$table->id = 1;
$table->name = 'Elisha Temiloluwa';
$table->email = '[email protected]';
$table->password = hash('SHA256', 'password');
$table->save();

$table->insert([
	'email' => '[email protected]', 'name' => 'Sam Orji', 
	'password' => hash('SHA256', 'passphr4s3'),
]);

$table->find([
	'email' => '[email protected]'
], );