PHP code example of eyroot / lx-simple-storage

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

    

eyroot / lx-simple-storage example snippets


use Lx\Storage\Factory as StorageFactory;
use Lx\Storage\StorageAbstract;

// initialize storage of type json
$storage = StorageFactory::create(
	StorageFactory::TYPE_JSON, 'items', array(
		'path' => '/path/directory/storage/json',
		StorageAbstract::FIELD_ID => 'id' // name of the id field
	)
);

// insert items
$storage->insert(array(
	'id' => 1,
	'title' => 'item 1'
));
$storage->insert(array(
	'id' => 2,
	'title' => 'item 2'
));

// get items by id
$item1 = $storage->getById(1);
$item2 = $storage->getById(2);

// update item with id 2
$storage->update(array('title' => 'item 2 title updated'), 2);

// retrieve items
$list = $storage->getList();

// delete item with id 1
$storage->delete(1);


use Lx\Storage\Factory as StorageFactory;
use Lx\Storage\StorageAbstract;

// initialize storage of type json
$storage = StorageFactory::create(
	StorageFactory::TYPE_JSON, 'items', array(
		'path' => '/path/directory/storage/json',
		StorageAbstract::FIELD_ID => 'id' // name of the id field,
		StorageAbstract::AUTOINCREMENT_ID => true
	)
);

// insert items
$storage->insert(array(
	'title' => 'item 1'
));
$storage->insert(array(
	'title' => 'item 2'
));

// get items by id
$item1 = $storage->getById(1);
$item2 = $storage->getById(2);