PHP code example of meyersm / simple-datastore

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

    

meyersm / simple-datastore example snippets


use meyersm\simpleDatastore;


use meyersm\simpleDatastore;

$datastore = new simpleDatastore("datastore-name");

$datastore->fish_hooks = 50;
$datastore->fish_names = array("bob","archibold","thomas");
$datastore->enable_fish= true;
$datastore['array_access'] = "yup";
$datastore[] = "new array entry";
$datastore->save();

$datastore->close();
//You can also call $datastore->save(true) to save then close in 1 line
$NEWdatastore = new simpleDatastore("datastore-name");
print $NEWdatastore->fish_hooks; //50
print $NEWdatastore['fish_names'][0] //bob

$datastore->destroy();

$datastore = new simpleDatastore("myDatastore",true);

$datastore = new simpleDatastore("myDatastore",false,true);
$datastore->complexClass = $CC;
$datastore->otherDatastore = $someOtherDatastore //You can even serialize other simpleDatastore objects if you like. 

$datastore = new simpleDatastore("teststore",false,false,"anotherDirectory"); //Different directory for datastore files
$teamB = new simpleDatastore(); //If you are going to change the error mode, you may want to wait to load the file instead of doing so at instantiation

$teamB->error_mode = simpleDatastore::$ERROR_MODE_SILENT; //Fails silently, will leave datastore null if error on read
$teamB->error_mode = simpleDatastore::$ERROR_MODE_DIE; //Dies on fatal error, ending script execution
$teamB->error_mode = simpleDatastore::$ERROR_MODE_EXCEPTION; //Default, throws exceptions on fatal errors
$teamB->open("teststore");

/**
* @param int $secondsBetweenLockAttempts Seconds to wait between lock attempts
* @param int $lockAttempts Number of tries to try and lock datastore
*/
public function setLockConfig($secondsBetweenLockAttempts=1,$lockAttempts=20)