PHP code example of sapistudio / filedatabase

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

    

sapistudio / filedatabase example snippets


use \SapiStudio\FileDatabase\Handler as Database;
$dbObject = Database::load($dbname,['dir' => 'path/to/database/dir','fields' => $[{field_name} => {field_type}]]);

$dbObject->removeDatabase();

$dbObject->exists();//return boolean

$rows = $dbObject->findAll();
    
foreach($rows as $row)
{
    print_r($row);
}

$row = $dbObject->get(1);
echo $row->id;

$dbObject->nickname = 'new_user';
$dbObject->save();

$row = $dbObject->get(1); //Edit row with ID 1
$row->nickname = 'edited_user';
$row->save();

$dbObject->get(1)->delete(); //Will remove row with ID 1

$dbObject->query()->where('name', '=', 'John')->find()->delete(); //Will remove John from DB

$dbObject->truncate();