PHP code example of olivier-ls / binary-storage-php

1. Go to this page and download the library: Download olivier-ls/binary-storage-php 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/ */

    

olivier-ls / binary-storage-php example snippets


use OlivierLS\BinaryStorage\BinaryStorage;

$store = new BinaryStorage(__DIR__ . '/data');

// Open (or create) a storage
$store->open('products');

// Write values
$store->set('products', 'product_123', [
    'name'  => 'MacBook Pro',
    'price' => 2499.99,
    'stock' => 42
]);

$store->set('products', 'product_456', ['name' => 'iPhone']);
$store->set('products', 'product_789', ['name' => 'iPad']);

// Save index
$store->saveIndex('products');

// Read a value
$product = $store->get('products', 'product_123');

// Prefix search
$list = $store->startsWith('products', 'product_');

// Substring search
$list = $store->contains('products', ['pad']);

// Compact the data file (optional)
$stats = $store->compact('products');

// Stats
print_r($store->stats('products'));

// Close
$store->close('products');