PHPackages                             sharkodlak/fluentdb - 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. sharkodlak/fluentdb

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

sharkodlak/fluentdb
===================

Fluent DB provides high performance DB layer with easy to use fluent interface.

07[1 issues](https://github.com/sharkodlak/fluentDb/issues)PHP

Since May 1Pushed 10y ago1 watchersCompare

[ Source](https://github.com/sharkodlak/fluentDb)[ Packagist](https://packagist.org/packages/sharkodlak/fluentdb)[ RSS](/packages/sharkodlak-fluentdb/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (2)Used By (0)

FluentDB
========

[](#fluentdb)

Fluent DB provides high performance DB layer with easy to use fluent interface. Inspired by NotORM and DibiFluent.

Use table film:

```
$db->film

```

Select all columns and all rows from table language:

```
$db->language->getQuery()->getResult()->fetchAll()

```

Select all rows from table actor, but let library to select only necessary columns:

```
foreach ($db->actor as $actor) {
	$actorName = $actor['first_name'] . ' ' . $actor['last_name'];
}

```

In previous example only columns actor\_id (as table primary key), first\_name and last\_name will be automatically selected in consecutive calls (in case of cache hit).

To get referenced table row, simply get table name from row. Library uses `Structure\Convention->foreignKey()` as source to match referenced table primary key identified by `Structure\Convention->primaryKey()`.

```
$row->language

```

To obtain referencing column value instead of referenced table, use column name.

```
$row['language_id']

```

Get corresponding rows from referenced table found by specified column. Method `Table->via()` specifies which column use from source table and optionaly from referenced table. This method returns one row. To find which rows references this value, method `Table->backwards()` shall be used. Method accepts optional arguments to specify column name from second table (defauts to foreign key referencing first table) and which column name to match in first table (defaults to primary key) - so these arguments are in opposite order against arguments from `Table->via()`. This method returns collection of corresponding rows.

```
foreach ($db->directory as $directory) {
	$parentDirectory = $directory->directory->via('parent_id');
	$subDirectories = $directory->directory->backwards('parent_id');
}

```

Row acts as an array, it can be iterated and method `toArray` returns all columns and values.

```
$row['name']; // Array access to column named 'name'
foreach ($row as $columnName => $value) { // Iterate over all columns
	$columnName . ': ' . $value;
}
$row->toArray(); // Get all columns as array

```

It's also possible to get one row from table defined by it's id.

```
$row = $db->film[$id]

```

To filter fetching rows from DB, use method where.

```
$db->film->where('release_year BETWEEN %s AND %s', 2001, 2008);

```

Features to be implemented later if it make sense
-------------------------------------------------

[](#features-to-be-implemented-later-if-it-make-sense)

Filter rows by data from another table

```
// Select all movies in German language
// SELECT film.* FROM film JOIN language USING (language_id) WHERE language.name = 'German'
$db->film->language->where('name = %s', 'German');
// Select actors having at least 3 films
// SELECT actor_id FROM film_actor GROUP BY actor_id HAVING COUNT(film_id) >= 30
$actorsHavingALotOfFilms = $db->film_actor->groupBy(̈́'actor_id')->having('COUNT(film_id) >= 30');
$db->actor->where(':id IN (%s)', $actorsHavingALotOfFilms);

```

It's possible to get referencing column value without knowledge of column name, the table name is required instead. Due to lazy loading it has no performance impact. Select from referenced table will performed only if another than primary key column will be used. This feature works only if DB has consistent Referential Integrity, because it mimics matching row in referenced table.

```
// Typical use is $row['language_id']
$row->language[':id']

```

Reference methods accepts array arguments to allow table referencing by compound key.

```
$row->target->via(['lang_id', 'second_id'], ['lang_id', 'second_id']);
$row->target->backwards(['lang_id', 'second_id'], ['lang_id', 'second_id']);

```

Reference methods also accept 3rd argument with comparison function. By default it's equality function, but more complex function can be used.

```
$between = function($rowColumnValue, $tableColumnValue) {
	...
	return $inBetween;
}
$row->target->via(null, null, $between);

```

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd42afcb9683d7f6a912dd3a976996e1faa454cc566ddd88f49286063d5cde01?d=identicon)[sharkodlak](/maintainers/sharkodlak)

---

Top Contributors

[![sharkodlak](https://avatars.githubusercontent.com/u/512785?v=4)](https://github.com/sharkodlak "sharkodlak (53 commits)")

### Embed Badge

![Health badge](/badges/sharkodlak-fluentdb/health.svg)

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

###  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)[pgvector/pgvector

pgvector support for PHP

198628.3k10](/packages/pgvector-pgvector)

PHPackages © 2026

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