Introduction

MicroDB is a minimalistic file-based JSON object database written in PHP.

Find the full, open source code at GitHub.

Features

  • Stores JSON objects as plain files
  • Concurrency safe
  • Arbitrary indices using custom key functions
  • Listen to database operations through events
  • Synchronize arbitrary operations

Basics

The following code demonstrates all basic operations on a MicroDB database.

<?php

    $db = new \MicroDB\Database('data/posts'); // data directory

    // create an item
    // id is an auto incrementing integer
    $id = $db->create(array(
    'title' => 'Lorem ipsum',
    'body' => 'At vero eos et accusam et justo duo dolores et ea rebum.'
    ));

    // load an item
    $post = $db->load($id);

    // save an item
    $post['tags'] = array('lorem', 'ipsum');
    $db->save($id, $post);

    // find items
    $posts = $db->find(function($post) {
    return is_array(@$post['tags']) && in_array('ipsum', @$post['tags']);
    });

    foreach($posts as $id => $post) {
    print_r($post);
    }

    // delete an item
    $db->delete($id);

Requirements

PHP 5.3+

Installation

The composer package name is morris/microdb. You can also download or fork the GitHub repository.