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

ActiveLibrary

slicks/fluentdb
===============

fluentdb allows the expressive writing of database queries and routines. fluentdb is fluent, which is intuitive as you can nearly guess what should come next even if you are just getting started with fluentdb. fluentdb is not an ORM. It was developed to allow folks coming from relational databases background write expressive queries with object interactions in mind. fluentdb has been tested with MySQL in this release; tests for other databases will be added as they complete.

04PHP

Since Oct 27Pushed 6y ago1 watchersCompare

[ Source](https://github.com/steveesamson/fluentdb)[ Packagist](https://packagist.org/packages/slicks/fluentdb)[ RSS](/packages/slicks-fluentdb/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

fluentdb
========

[](#fluentdb)

fluentdb allows the expressive writing of database queries and routines. fluentdb is fluent, which is intuitive as you can nearly guess what should come next even if you are just getting started with fluentdb. fluentdb is not an ORM. It was developed to allow folks coming from relational databases background write expressive queries with object interactions in mind. fluentdb has been tested with MySQL in this release; tests for other databases will be added as they complete.

\##fluentdb options fluentdb takes all the options/config allowed by `PDO`. Please see  for details. It also has, in addition, `debug_db` option which could be `true/false`. `debug_db` enables the logging of the raw queries to the console when it is set to *true*, useful while developing.

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

[](#installation)

```
  composer require slicks/fluentdb

```

Usage
-----

[](#usage)

Using fluentdb is pure joy:

```
       use slicks\db\DbConnectionFactory as DbFac;
       $options = [
                      'host' => 'devmac',
                      'port' => '3306',
                      'username' => 'tester',
                      'database' => 'todo_db',
                      'password' => 'tester'
                  ];

       //Init Db factory;
       DbFac::init($options);
       //Let us now connect and get a db object
       $db = DbFac::getDb();
       //Do db stuffs here

```

fluentdb in action
------------------

[](#fluentdb-in-action)

Now that we have a valid `db` object, how do we use it? Well, see the following:

`fetch`ing records
------------------

[](#fetching-records)

```

    $db->fetch('todo', function ($e, $rows) {
        if ($e) {
            throw new Exception($e);
        }
        print_r($rows);
    });

```

The above is used when all record fields are needed. However, if a subset of the fields are of interest, **`select`** with **`from`** and **`fetch`** is the way to go.

`select`ing records
-------------------

[](#selecting-records)

```

         $db->select('id, task')
             ->from('todo')
             ->fetch(function ($e, $rows) {
                 if ($e) {
                     throw new Exception($e);
                 }
                 print_r($rows);
             });

```

`query`ing records with `query`
-------------------------------

[](#querying-records-with-query)

```
    $q = "insert into todo (task, task_owner) values ('Vacuum the floor',1),('Iron my shirt', 1)";
    $this->db->query($q, function ($e, $res) {
        if ($e) {
            throw new Exception($e);
        }
       print_r($res);
    });

```

**Note:** The use of ONLY **`fetch`** or in conjunction with **`select`** and **`from`** does not change the outcome. I think it just depends on what flavour you like or the need at hand. That being said, all the examples are written in one or other flavour but what was done in one flavour can equally be done in the other flavour.

### `where`

[](#where)

```
     $db->where('id', 1)
        ->fetch('todo', function ($err, $rows) {
             if ($err) {
                 throw new Exception($err);
             }
              print_r($rows);
         });
```

```
     $db->where('id >', 1)
       ->fetch('todo', function ($err, $rows) {
             if ($err) {
                  throw new Exception($err);
              }
               print_r($rows);
         });
```

```
     $db->where('id =', 1)
        ->fetch('todo', function ($err, $rows) {
             if ($err) {
                   throw new Exception($err);
               }
                print_r($rows);
         });
```

```
     $db->where('id ', 2)
      ->fetch(function ($err, $rows) {
              if ($err) {
                    throw new Exception($err);
              }
              print_r($rows);
      });
```

### `orHaving` for aggregates

[](#orhaving-for-aggregates)

```
    $db->select('o.name, count(*) tasks')
      ->from('task_owners o')
      ->join('todo t', 't.task_owner = o.id', 'left')
      ->groupBy('o.name')
      ->having('tasks >', 2)
      ->orHaving('tasks', 3)
      ->fetch(function ($err, $rows) {
              if ($err) {
                    throw new Exception($err);
              }
              print_r($rows);
      });
```

`insert`ing records
-------------------

[](#inserting-records)

### `insert` - single record per insert

[](#insert---single-record-per-insert)

```
    $db->insert('task_owners', ['name' => 'Test owner'], function ($e, $res) {
        if ($e) {
            throw new Exception($e);
        }
        echo($res->id);
    });
```

### inserting multiple records with `query`

[](#inserting-multiple-records-with-query)

```
        $q = "insert into todo (task, task_owner) values ('Vacuum the floor',1),('Iron my shirt', 1)";
        $db->query($q, function ($e, $res) {
            if ($e) {
                throw new Exception($e);
            }
            echo($res->affectedRows);
        });
```

### `update`ing records

[](#updateing-records)

```
       $db->set('task', 'Updated Todo')
           ->set('earnings', 0.99)
           ->whereIn('id', [1,3])
           ->update('todo', function ($e, $res) {
               if ($e) {
                   throw new Exception($e);
               }
               echo($res->affectedRows);
           });
```

### `delete`ing records

[](#deleteing-records)

```
       $db->where('id', 2)
           ->delete('todo', function ($e, $res) {
               if ($e) {
                   throw new Exception($e);
               }

               echo($res->affectedRows);
           });
```

Test
----

[](#test)

Before running the tests, load the included script **test\_scripts.sql** onto your mysql database. Ensure to load the script as 'root' for you need to grant privileges. Update the tests/specs.php with your database parameters. Thereafter, run;

```
    vendor/bin/peridot tests/specs

```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

---

Top Contributors

[![steveesamson](https://avatars.githubusercontent.com/u/6529888?v=4)](https://github.com/steveesamson "steveesamson (13 commits)")

### Embed Badge

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

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

PHPackages © 2026

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