PHPackages                             grantjm9992/pdo-helper - 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. grantjm9992/pdo-helper

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

grantjm9992/pdo-helper
======================

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

1.0.8(4y ago)02.7k1[1 issues](https://github.com/grantjm9992/pdo-helper/issues)Apache-2.0PHPPHP ^7.1

Since Jul 5Pushed 4y ago1 watchersCompare

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

READMEChangelogDependencies (2)Versions (10)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

Versions
--------

[](#versions)

#### Version 2.x

[](#version-2x)

The stable release of FluentPDO and actively maintained. Officially supports PHP 7.3 to PHP 8.0, but it can work with previous versions of PHP 7.

#### Version 1.x

[](#version-1x)

The legacy release of FluentPDO. It is no longer supported and will not be maintained or updated. This version works with PHP 5.4 to 7.1.

#### Version 3.x - alpha

[](#version-3x---alpha)

This version is a full rewrite of Fluent from the ground up. Its main advantage is significantly less memory usage and much greater performance in query building. It also places a few additional restrictions to make queries easier to read and maintain. Documentation has also been a very common request, and version 3 is being fully documented alongside development. Details and metrics will be posted once available.

Reference
---------

[](#reference)

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

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

[](#installation)

### Composer

[](#composer)

The preferred way to install FluentPDO is via [composer](http://getcomposer.org/).

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

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

```

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

### Download Zip

[](#download-zip)

If you prefer not to use composer, download the latest release, 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)->fetch();
$query = $fluent->from('user', 1)->fetch(); // 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

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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 ~5 days

Total

9

Last Release

1731d ago

### Community

Maintainers

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

---

Tags

databasemysqldbalpdooraclequerybuilderfluentdb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/grantjm9992-pdo-helper/health.svg)

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

###  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)
