PHPackages                             amund/pdo-silo - 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. amund/pdo-silo

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

amund/pdo-silo
==============

A silo to store and link resources, via a simple API.

1.0.2(3w ago)02MITPHPPHP &gt;=8.1

Since May 17Pushed 3w ago1 watchersCompare

[ Source](https://github.com/Amund/pdo-silo)[ Packagist](https://packagist.org/packages/amund/pdo-silo)[ RSS](/packages/amund-pdo-silo/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (4)Used By (0)

PDO-Silo
========

[](#pdo-silo)

A silo to store and link resources, via a simple API.

[![Latest Stable Version](https://camo.githubusercontent.com/1036208d20234dbd8476774a2b01886b259eb2080ebe0a0b1ba36b9162405631/68747470733a2f2f706f7365722e707567782e6f72672f616d756e642f70646f2d73696c6f2f762f737461626c65)](https://packagist.org/packages/amund/pdo-silo)

**License:** MIT
**PHP:** 8.1+
**Drivers:** MySQL, SQLite, PostgreSQL

---

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

[](#installation)

```
composer require amund/pdo-silo
```

Quick Overview
--------------

[](#quick-overview)

```
use Silo\Silo;

// 1. Connect and create tables
$pdo = new \PDO('mysql:host=localhost;dbname=mydb;charset=utf8', 'login', 'password');
$silo = new Silo($pdo, 'test');
$silo->create();

// 2. Create resources (returns their ids)
$john  = $silo->set('person', ['firstname' => 'John', 'lastname' => 'Doe']);
$cynth = $silo->set('person', ['firstname' => 'Cynthia', 'lastname' => 'Doe']);
$regis = $silo->set('person', ['firstname' => 'Régis', 'lastname' => 'Doe']);
// $john = 1, $cynth = 2, $regis = 3

// 3. Read a resource
$silo->get($john);
// => ['id' => 1, 'class' => 'person', 'firstname' => 'John', 'lastname' => 'Doe']

// 4. Modify an attribute
$silo->setAttr($john, 'gender', 'M');

// 5. Link resources
$silo->link($john, $cynth, 'married_to');
$silo->link($regis, $john, 'son_of');

// 6. Read with links
$silo->get($john, links: true);
// => ['id' => 1, 'class' => 'person', ..., 'links' => [
//       'from' => ['married_to' => [2]],      // people linked TO John
//       'to'   => ['son_of' => [3]],           // people John links TO
//     ], 'lists' => [
//       'from' => [],                           // ordered lists John belongs to
//       'to'   => [],                           // ordered lists John owns
//     ]]

// 7. Search (accepts int values natively)
$silo->search(['where' => $silo->filter('age', '>=', 18)]);

$silo->search(['where' => $silo->filter('lastname', 'LIKE', '%Doe%')]);
// => ['total' => 3, 'results' => [1, 2, 3], 'duration' => '0.000123']

// 8. Ordered lists
$tagA = $silo->set('tag');
$tagB = $silo->set('tag');
$silo->setList($john, 'tags', [$tagA, $tagB]);
$silo->getList($john, 'tags'); // => [$tagA, $tagB]
```

API
---

[](#api)

### Silo lifecycle

[](#silo-lifecycle)

MethodDescription`__construct(\PDO $pdo, string $prefix = 'resource')`Create a Silo instance.`create(): void`Create the 4 database tables (`PREFIX_meta`, `PREFIX_attribute`, `PREFIX_link`, `PREFIX_cache`)`destroy(): void`Drop all 4 tables### Resources

[](#resources)

MethodDescription`set(string $class, array $attributes = [], bool $get = false): int|array`Create a resource. Returns its id (or full resource if `$get` is true).`get(int $id, bool $links = false, bool $getLinks = false): ?array`Retrieve a resource by id. Optionally include its links.`getMeta(int $id): ?array`Returns `['id', 'class']` or null.`setMeta(?int $id, string $class): int`Create (`$id = null`) or update a resource class. Returns the resource id.`getAttr(int $id, string $attr): ?string`Returns the attribute value, or null.`setAttr(int $id, string $attr, mixed $value): mixed`Set/update/delete an attribute. `null` and `''` delete the attribute. `'0'` and `0` are stored.`getAttributes(int $id): array`Returns all attributes as `['name' => 'value', ...]`.`setAttributes(int $id, ?array $attributes): ?array`Replace all attributes, or pass `null` to delete them all.### Links

[](#links)

MethodDescription`link(int $from, int $to, ?string $attribute = null): bool`Create a link. Default attribute = target class name.`unlink($from, $to): bool`Remove a specific link, all links from, all links to, or all links for an id.`linkFrom(int $id, bool $get = false): array`Get child links, grouped by attribute.`linkTo(int $id, bool $get = false): array`Get parent links, grouped by attribute.`getList(int $parent, string $attribute): array`Get an ordered list of linked resources (by position).`setList(int $parent, string $attribute, array $children): void`Replace an ordered list.`listFrom(int $id, bool $get = false): array`Get list children, grouped by attribute.`listTo(int $id, bool $get = false): array`Get list parents, grouped by attribute.### Search

[](#search)

MethodDescription`search(array $arg = [], bool $get = false, bool $links = false, bool $getLinks = false): array`Search resources. Returns `['total', 'results', 'duration']`. Supports `where`, `order`, `limit`, and `offset` keys.`filter(string $field, string $operator, string|int|float|array $value): string`Build a WHERE clause fragment. Operators: `=`, `!=`, ``, `=`, `LIKE`, `IN`. `int`/`float` values produce numeric comparisons.`group(string $operator, string ...$filters): string`Combine filters with `AND` or `OR`.### Cache

[](#cache)

MethodDescription`emptyCache(): void`Clear all cached resources.Running Tests
-------------

[](#running-tests)

```
composer test          # runs vendor/bin/phpunit
```

Tests use SQLite `:memory:`. Each test creates and destroys its own silo.

Static Analysis
---------------

[](#static-analysis)

```
composer phpstan       # runs vendor/bin/phpstan analyse
composer check         # runs phpstan + tests
```

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- `ext-pdo` (required)
- `ext-pdo_mysql` (for MySQL), `ext-pdo_sqlite` (for SQLite), or `ext-pdo_pgsql` (for PostgreSQL)

About
-----

[](#about)

The idea behind PDO-Silo is to provide a minimal persistence layer for PHP projects — a nano ORM / DBAL. It is simple, small, fast, and fun to use.

Built by [Dimitri Avenel](https://github.com/Amund). Originally created in 2016.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance95

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

3

Last Release

23d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/16551810b8c56652cdcf583129be4fa53502818c9a0c5122960ccbce48132720?d=identicon)[Amund](/maintainers/Amund)

---

Top Contributors

[![Amund](https://avatars.githubusercontent.com/u/121880?v=4)](https://github.com/Amund "Amund (11 commits)")

---

Tags

persistenceormpdoSimplestorage

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/amund-pdo-silo/health.svg)

```
[![Health](https://phpackages.com/badges/amund-pdo-silo/health.svg)](https://phpackages.com/packages/amund-pdo-silo)
```

###  Alternatives

[doctrine/doctrine-bundle

Symfony DoctrineBundle

4.8k249.9M3.9k](/packages/doctrine-doctrine-bundle)[doctrine/persistence

The Doctrine Persistence project is a set of shared interfaces and functionality that the different Doctrine object mappers share.

4.0k298.2M955](/packages/doctrine-persistence)[propel/propel

Propel2 is an open-source Object-Relational Mapping (ORM) for PHP.

1.3k5.5M112](/packages/propel-propel)[propel/propel1

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

8361.6M87](/packages/propel-propel1)[propel/propel-bundle

Integration of Propel in Symfony

181907.3k54](/packages/propel-propel-bundle)[morris/lessql

LessQL: A lightweight and performant PHP ORM alternative

404143.1k3](/packages/morris-lessql)

PHPackages © 2026

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