PHPackages                             xety/fluentpdo - 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. xety/fluentpdo

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

xety/fluentpdo
==============

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

v2.1.4(5y ago)07Apache-2.0PHP

Since Feb 24Pushed 5y agoCompare

[ Source](https://github.com/Xety/fluentpdo)[ Packagist](https://packagist.org/packages/xety/fluentpdo)[ Docs](https://github.com/envms/fluentpdo)[ RSS](/packages/xety-fluentpdo/feed)WikiDiscussions master Synced today

READMEChangelog (2)DependenciesVersions (29)Used By (0)

FluentPDO [![Build Status](https://camo.githubusercontent.com/b64412308e1025f5d34685862b53c06ae00fa624e7a41b2e81b6846957fe8162/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f656e766d732f666c75656e7470646f2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/envms/fluentpdo) [![Maintainability](https://camo.githubusercontent.com/74ddbdc6f119f1ad46ac6ddcc37de33d943d77e94418019281d6eb08fd5f346b/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f31393231306361393163373035356238393730352f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/fpdo/fluentpdo/maintainability)
=================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#fluentpdo--)

FluentPDO is a PHP SQL query builder using PDO. It's a quick and light library featuring a smart join builder, which automatically creates table joins for you.

Features
--------

[](#features)

- Easy interface for creating robust queries
- Supports any database compatible with PDO
- Ability to build complex SELECT, INSERT, UPDATE &amp; DELETE queries with little code
- Type hinting for magic methods with code completion in smart IDEs

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

[](#requirements)

The latest (2.x) release of FluentPDO officially supports PHP 7.1, 7.2 and 7.3. v2.x is actively maintained.

The legacy (1.x) release of FluentPDO works with PHP 5.4 to 7.1. **Note:** v1.x is no longer supported and will not be maintained or updated.

Reference
---------

[](#reference)

[Sitepoint - Getting Started with FluentPDO](http://www.sitepoint.com/getting-started-fluentpdo/)

Install
-------

[](#install)

### Composer

[](#composer)

The preferred way to install FluentPDO is via [composer](http://getcomposer.org/). Version 2.0 is now released! Please start using 2.x in your projects and let us know of any issues you find, they will be resolved quickly.

Add the following line in your `composer.json` file:

```
"require": {
	...
	"envms/fluentpdo": "^2.1.0"
}

```

update your dependencies with `composer update`, and you're done!

### Copy

[](#copy)

If you prefer not to use composer, create the directory `Envms/FluentPDO` in your library directory, and drop this repository into it. Finally, add:

```
require "[lib-dir]/Envms/FluentPDO/src/Query.php";
```

to the top of your application. **Note:** You will need an autoloader to use FluentPDO without changing its source code.

Getting Started
---------------

[](#getting-started)

Create a new PDO instance, and pass the instance to FluentPDO:

```
$pdo = new PDO("mysql:dbname=fluentdb", "root");
$fluent = new \Envms\FluentPDO\Query($pdo);
```

Then, creating queries is quick and easy:

```
$query = $fluent->from('comment')
             ->where('article.published_at > ?', $date)
             ->orderBy('published_at DESC')
             ->limit(5);
```

which would build the query below:

```
SELECT comment.*
FROM comment
LEFT JOIN article ON article.id = comment.article_id
WHERE article.published_at > ?
ORDER BY article.published_at DESC
LIMIT 5
```

To get data from the select, all we do is loop through the returned array:

```
foreach ($query as $row) {
    echo "$row[title]\n";
}
```

Using the Smart Join Builder
----------------------------

[](#using-the-smart-join-builder)

Let's start with a traditional join, below:

```
$query = $fluent->from('article')
             ->leftJoin('user ON user.id = article.user_id')
             ->select('user.name');
```

That's pretty verbose, and not very smart. If your tables use proper primary and foreign key names, you can shorten the above to:

```
$query = $fluent->from('article')
             ->leftJoin('user')
             ->select('user.name');
```

That's better, but not ideal. However, it would be even easier to **not write any joins**:

```
$query = $fluent->from('article')
             ->select('user.name');
```

Awesome, right? FluentPDO is able to build the join for you, by you prepending the foreign table name to the requested column.

All three snippets above will create the exact same query:

```
SELECT article.*, user.name
FROM article
LEFT JOIN user ON user.id = article.user_id
```

##### Close your connection

[](#close-your-connection)

Finally, it's always a good idea to free resources as soon as they are done with their duties:

```
$fluent->close();
```

CRUD Query Examples
-------------------

[](#crud-query-examples)

##### SELECT

[](#select)

```
$query = $fluent->from('article')->where('id', 1);
$query = $fluent->from('user', 1); // shorter version if selecting one row by primary key
```

##### INSERT

[](#insert)

```
$values = array('title' => 'article 1', 'content' => 'content 1');

$query = $fluent->insertInto('article')->values($values)->execute();
$query = $fluent->insertInto('article', $values)->execute(); // shorter version
```

##### UPDATE

[](#update)

```
$set = array('published_at' => new FluentLiteral('NOW()'));

$query = $fluent->update('article')->set($set)->where('id', 1)->execute();
$query = $fluent->update('article', $set, 1)->execute(); // shorter version if updating one row by primary key
```

##### DELETE

[](#delete)

```
$query = $fluent->deleteFrom('article')->where('id', 1)->execute();
$query = $fluent->deleteFrom('article', 1)->execute(); // shorter version if deleting one row by primary key
```

***Note**: INSERT, UPDATE and DELETE queries will only run after you call `->execute()`*

Full documentation can be found on the [FluentPDO homepage](http://envms.github.io/fluentpdo/)

License
-------

[](#license)

Free for commercial and non-commercial use under the [Apache 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) or [GPL 2.0](http://www.gnu.org/licenses/gpl-2.0.html) licenses.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 72.1% 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 ~103 days

Recently: every ~159 days

Total

20

Last Release

2123d ago

Major Versions

v1.1.2 → v2.0.0-alpha12017-11-22

v1.1.3 → v2.0.0-alpha22018-08-26

### Community

Maintainers

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

---

Top Contributors

[![cbornhoft](https://avatars.githubusercontent.com/u/10536543?v=4)](https://github.com/cbornhoft "cbornhoft (181 commits)")[![sanabria91](https://avatars.githubusercontent.com/u/24279172?v=4)](https://github.com/sanabria91 "sanabria91 (17 commits)")[![maldoinc](https://avatars.githubusercontent.com/u/1253062?v=4)](https://github.com/maldoinc "maldoinc (17 commits)")[![StefanYohansson](https://avatars.githubusercontent.com/u/1783252?v=4)](https://github.com/StefanYohansson "StefanYohansson (7 commits)")[![jkufner](https://avatars.githubusercontent.com/u/16572?v=4)](https://github.com/jkufner "jkufner (6 commits)")[![cj-clx](https://avatars.githubusercontent.com/u/46033285?v=4)](https://github.com/cj-clx "cj-clx (4 commits)")[![maratK13](https://avatars.githubusercontent.com/u/3388197?v=4)](https://github.com/maratK13 "maratK13 (2 commits)")[![dczech](https://avatars.githubusercontent.com/u/2190435?v=4)](https://github.com/dczech "dczech (2 commits)")[![Xety](https://avatars.githubusercontent.com/u/8210023?v=4)](https://github.com/Xety "Xety (2 commits)")[![mta59066](https://avatars.githubusercontent.com/u/936941?v=4)](https://github.com/mta59066 "mta59066 (1 commits)")[![pkoutsias](https://avatars.githubusercontent.com/u/5034122?v=4)](https://github.com/pkoutsias "pkoutsias (1 commits)")[![tmihalik](https://avatars.githubusercontent.com/u/440762?v=4)](https://github.com/tmihalik "tmihalik (1 commits)")[![Alpine418](https://avatars.githubusercontent.com/u/4191615?v=4)](https://github.com/Alpine418 "Alpine418 (1 commits)")[![yurirnascimento](https://avatars.githubusercontent.com/u/4502631?v=4)](https://github.com/yurirnascimento "yurirnascimento (1 commits)")[![BenLorantfy](https://avatars.githubusercontent.com/u/4398635?v=4)](https://github.com/BenLorantfy "BenLorantfy (1 commits)")[![dima-stefantsov](https://avatars.githubusercontent.com/u/1370909?v=4)](https://github.com/dima-stefantsov "dima-stefantsov (1 commits)")[![gsouf](https://avatars.githubusercontent.com/u/3215399?v=4)](https://github.com/gsouf "gsouf (1 commits)")[![jay-knight](https://avatars.githubusercontent.com/u/42975397?v=4)](https://github.com/jay-knight "jay-knight (1 commits)")[![Jazz-Man](https://avatars.githubusercontent.com/u/6892898?v=4)](https://github.com/Jazz-Man "Jazz-Man (1 commits)")[![jk3us](https://avatars.githubusercontent.com/u/41621?v=4)](https://github.com/jk3us "jk3us (1 commits)")

---

Tags

databasemysqldbalpdooraclequerybuilderfluentdb

### Embed Badge

![Health badge](/badges/xety-fluentpdo/health.svg)

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

###  Alternatives

[envms/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

925511.7k13](/packages/envms-fluentpdo)[lichtner/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921274.8k6](/packages/lichtner-fluentpdo)[fpdo/fluentpdo

FluentPDO is a quick and light PHP library for rapid query building. It features a smart join builder, which automatically creates table joins.

921244.9k7](/packages/fpdo-fluentpdo)[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[dibi/dibi

Dibi is Database Abstraction Library for PHP

5013.8M120](/packages/dibi-dibi)[aura/sqlquery

Object-oriented query builders for MySQL, Postgres, SQLite, and SQLServer; can be used with any database connection library.

4572.9M34](/packages/aura-sqlquery)

PHPackages © 2026

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