PHPackages                             almacil/php-database - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. almacil/php-database

ActiveLibrary[Database &amp; ORM](/categories/database)

almacil/php-database
====================

A simple flat file database designed to persist data using just PHP and flat files. Perfect solution when no other database is available or for small projects.

1.0.1(4y ago)19321MITPHPPHP &gt;=7.0.0

Since Aug 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/rubenperezlopez/almacil-php-database)[ Packagist](https://packagist.org/packages/almacil/php-database)[ RSS](/packages/almacil-php-database/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (3)Used By (1)

[![GitHub last commit](https://camo.githubusercontent.com/cbe1c5bde86aa00de28a8fa00e5b0f85affce5bb9435bfc86736ebed97f0e677/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f727562656e706572657a6c6f70657a2f616c6d6163696c2d7068702d6461746162617365)](https://camo.githubusercontent.com/cbe1c5bde86aa00de28a8fa00e5b0f85affce5bb9435bfc86736ebed97f0e677/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f727562656e706572657a6c6f70657a2f616c6d6163696c2d7068702d6461746162617365)[![GitHub tag (latest by date)](https://camo.githubusercontent.com/96b18bb873cdd273a9fa593b8128dd8821b75b6818d8d72305aac691b266887e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f727562656e706572657a6c6f70657a2f616c6d6163696c2d7068702d64617461626173653f6c6162656c3d6c61737425323076657273696f6e)](https://camo.githubusercontent.com/96b18bb873cdd273a9fa593b8128dd8821b75b6818d8d72305aac691b266887e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f727562656e706572657a6c6f70657a2f616c6d6163696c2d7068702d64617461626173653f6c6162656c3d6c61737425323076657273696f6e)[![Packagist PHP Version Support](https://camo.githubusercontent.com/4e8e3b8a45a9bc75abcf0ac3d583db3f07d74c02c26f8af614805c798327ac6f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616c6d6163696c2f7068702d6461746162617365)](https://camo.githubusercontent.com/4e8e3b8a45a9bc75abcf0ac3d583db3f07d74c02c26f8af614805c798327ac6f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f616c6d6163696c2f7068702d6461746162617365)[![GitHub](https://camo.githubusercontent.com/b04c076532529a77e2356fbc666a78350cab9b230eb8d655ff0f3e789ef2b220/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f727562656e706572657a6c6f70657a2f616c6d6163696c2d7068702d6461746162617365)](https://camo.githubusercontent.com/b04c076532529a77e2356fbc666a78350cab9b230eb8d655ff0f3e789ef2b220/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f727562656e706572657a6c6f70657a2f616c6d6163696c2d7068702d6461746162617365)

🗃 Almacil PHP Database
======================

[](#-almacil-php-database)

This is a simple **flat file** NoSQL like database implemented in PHP for small projects without any third-party dependencies that store data in plain JSON files.

*Do you want to contribute?*
[![Donate 1€](https://camo.githubusercontent.com/e9f10e402d347eae203f34b35b454643412c5923154e1d43b9475c32c32114cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275792532306d6525323061253230636f666665652d312545322538322541432d627269676874677265656e3f6c6f676f3d6275796d6561636f66666565266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d67726579267374796c653d666f722d7468652d6261646765)](https://www.paypal.com/paypalme/rubenperezlopez/1?target=_blank)

Features
--------

[](#features)

- Lightweight and Secure
- Easy to get started
- No external dependencies
- CRUD (create, read, update, delete) operations
- Supports multiple databases and tables/collections

Installation
------------

[](#installation)

Installation is possible using Composer

```
composer requiere almacil/php-database
```

Usage
-----

[](#usage)

### Summary

[](#summary)

```
// Create instance
$db = new \Almacil\Database($database);

// Basic
$db->find($collection, /* function to find */);
$db->insert($collection, $item);
$db->update($collection, /* function to find */, $update);
$db->remove($collection, /* function to find */, $permanent);

// More
$db->count($collection, /* function to find */);
$db->findOne($collection, /* function to find */);
$db->upsert($collection, /* function to find */, $update);
$db->drop($collection);
$db->newid();
```

### Create instance

[](#create-instance)

Create an instance of \\Almacil\\Database. Optionally, we can maintain the order of the databases and collections with a hierarchy using slash. We can also decide that the directory corresponds to a database and create another instance for another database in another directory.

```
// Require composer autoloader
require __DIR__ . '/vendor/autoload.php';

// Directory containing the json files of databases
$database = __DIR__ . '/data';

// Create de instance
$db = new \Almacil\Database($database);

// "database/collection" or "collection" or "collection/subcollection"
$collection = 'mycollection/mysubcollection';
```

### Find

[](#find)

```
// ... after insert

$find = new stdClass();
$find->_id = $newItem->_id;

$items = $db->update($collection, function($item) use ($find) {
    return $find->_id === $item->_id;
});
```

### Insert

[](#insert)

```
// ... after create instance $db
$item = new stdClass();
$item->name = 'Rubén';
$newItem = $db->insert($collection, $item);
```

### Update

[](#update)

```
// ... after insert

$find = new stdClass();
$find->_id = $newItem->_id;

$update = new stdClass();
$update->name = 'Rubén Pérez';

$numberItemsUpdated = $db->update($collection, function($item) use ($find) {
    return $find->_id === $item->_id;
}, $update);
```

### Remove

[](#remove)

When we delete an element, we don't really delete it but we set the *\_removed\_at* field with the value of microtime(). If we want to delete the element permanently we will send true in the third argument.

```
// ... after insert

$find = new stdClass();
$find->_id = $newItem->_id;

$permanent = true;

$numberItemsRemoved = $db->remove($collection, function($item) use ($find) {
    return $find->_id === $item->_id;
}, $permanent);
```

*Do you want to contribute?*
[![Donate 1€](https://camo.githubusercontent.com/e9f10e402d347eae203f34b35b454643412c5923154e1d43b9475c32c32114cc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4275792532306d6525323061253230636f666665652d312545322538322541432d627269676874677265656e3f6c6f676f3d6275796d6561636f66666565266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d67726579267374796c653d666f722d7468652d6261646765)](https://www.paypal.com/paypalme/rubenperezlopez/1?target=_blank)

---

Made with ❤️ by developer for developers

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1791d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f0782da3f221895ff5593718ad68bf60aacf897dffb9dc462929346fc16e105?d=identicon)[rubenperezlopez](/maintainers/rubenperezlopez)

---

Top Contributors

[![rubenperezlopez](https://avatars.githubusercontent.com/u/26804440?v=4)](https://github.com/rubenperezlopez "rubenperezlopez (1 commits)")

### Embed Badge

![Health badge](/badges/almacil-php-database/health.svg)

```
[![Health](https://phpackages.com/badges/almacil-php-database/health.svg)](https://phpackages.com/packages/almacil-php-database)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
