PHPackages                             crocodile2u/tinyorm - 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. crocodile2u/tinyorm

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

crocodile2u/tinyorm
===================

v1.1.12(8y ago)21876MITPHPPHP &gt;=5.4.0

Since Oct 12Pushed 8y ago2 watchersCompare

[ Source](https://github.com/crocodile2u/tinyorm)[ Packagist](https://packagist.org/packages/crocodile2u/tinyorm)[ RSS](/packages/crocodile2u-tinyorm/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (1)Versions (21)Used By (0)

tinyorm
=======

[](#tinyorm)

Very minimalistic ORM &amp; DB tools for PHP

Why yet another library?
========================

[](#why-yet-another-library)

I know quite a lot of similar projects but they all don't satisfy me. Therefore, I made a list of requirements that my perfect ORM library should meet.

- It should be tiny. I don't want to have tons of classes added to my next project just because I want to automate database routines.
- It should not be too smart. It should help me to perform ordinary tasks and stay as much under control as possible.
- It should not generate DB schema. For migrations I will use special instruments.
- No lazy-loading of related objects. No this magic, no behind-the-scene bullshit.
- No weird aliases in SQL like *SELECT \* FROM \\model\\Foo JOIN \\model\\Bar ...*
- Thin entities that do not contain any buisiness logic or even the storage-specific logic (relations etc). This makes things overcomplicated and results in less control from the developer. Separation of persistence logic from the entities makes them reusable even when you switch storage backends. While this is not often needed, this is a handy feature which is easily achievable. Moreover, sometimes I would like, for example, to access the same entity in different ways: for example, if I have a table which I want to access via both MySQL &amp; Handlersocket.
- A Query-Object implementation with a neat interface. I usually prefer to write SQL queries by hand. However, there are cases when the query needs to be formed dynamically, and in such cases an object with clean interface is a great advantage over composing SQL string by hand.
- It should be able of handling multiple DB connections. Ideally it should have a transaction manager which issues BEGIN/COMMIT/ROLLBACK for all connections participating in DB interactions.
- Ideally it should have a scaffolding utility to generate entities from DB tables.

While there are tools that conform to some of the requirements, I failed to find a library that has it all.

Show me the code!
=================

[](#show-me-the-code)

Select usage:

```
$select = (new Select("my_table"))
    ->join("LEFT JOIN another_table USING (join_column)")
    ->where("filter_column = ?", $filterColumnValue)
    ->setConnection($db);
$count = $select->count("DISTINCT id");
$rows = $select->execute()->fetchAll(\PDO::FETCH_ASSOC);
```

You can set fetch modes for Select:

```
$select->setFetchMode(\PDO::FETCH_ASSOC);
$select->setFetchClass(MyTableEntity::class);
$select->setFetchInto(new MyTableEntity());
```

Working with multiple DB connections:

```
$txManager = new \tinyorm\TxManager();
$txManager->registerConnection($this->connection)
    ->registerConnection($this->connection2);

$result = $txManager->atomic(function () {
    $this->connection->exec("INSERT INTO test (c_unique) VALUES ('val1')");
    $this->connection2->exec("INSERT INTO test (c_unique) VALUES ('val2')");
    return true;
});
```

This way, if anything goes wrong with the first or the second INSERT, transactions in both connection will be rolled back, no rows will be inserted. On the other hand, if everything goes fine, transactions in both connection will be commited.

Transaction manager supports nested transactions, and the tinyorm\\Db class also supports them.

The approach
============

[](#the-approach)

I used an approach similar to that of Zend Framework 2 (  ). The entity classes are just simple data containers that do not have DB connection/persistence logic. However, in the end, tinyorm entities do have minimal "knowledge" about their relationship to a storage layer. First, they have *getSourceName()* method which essentially is meant to return a storage table/collection name. Second, there are *getPK()* and *setPK()* methods to access primary key. The name primary key column is stored in protected *pkName* property. And finally, entities have *getSequenceName()*. I made all this for the sake of simplicity, in order not to have to introduce more classes. tinyorm only supports *AUTO\_INCREMENT*'ed primary keys. In contracts to Zend Framework 2, all the stuff related to persistence is just a few classes/interfaces:

- DbInterface - the interface for Db connector
- Db - a wrapper around PDO
- persistence\\Driver - the interface for persistence driver
- persistence\\DbDriver - persistence driver implementation with Db/PDO (thus RDBMS) as backend. Only tested with MySQL, though should also work fine with Postgres and Sqlite
- persistence\\HsDriver - persistence driver implementation with handlersocket as backend.

Persistence driver operates on Entities. In case of ZF2, we can talk about their *Table Gateway* as a persistence driver. See the link above for reference. In tinyorm, things are way more simple. You just create a persistence driver instance and call its' *save()*, *insert()*, *update()*, *delete()* methods providing an Entity as an argument.

For a query object, I took a look at Phalcon framework ( [https://docs.phalconphp.com/en/latest/api/Phalcon\_Mvc\_Model\_Query\_Builder.html](https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_Model_Query_Builder.html) ). However, I modified the interface a little, so I find it a little bit better.

I also implemented a database transaction manager capable of handling multiple DB connections.

Credits
=======

[](#credits)

Thanks RasmiKanta Moharana () for early feedback &amp; spotting bugs in the example app!

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% 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 ~27 days

Recently: every ~36 days

Total

20

Last Release

3033d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1736820?v=4)[Victor Bolshov](/maintainers/crocodile2u)[@crocodile2u](https://github.com/crocodile2u)

---

Top Contributors

[![crocodile2u](https://avatars.githubusercontent.com/u/1736820?v=4)](https://github.com/crocodile2u "crocodile2u (62 commits)")[![topjor](https://avatars.githubusercontent.com/u/6335056?v=4)](https://github.com/topjor "topjor (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/crocodile2u-tinyorm/health.svg)

```
[![Health](https://phpackages.com/badges/crocodile2u-tinyorm/health.svg)](https://phpackages.com/packages/crocodile2u-tinyorm)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/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)
