PHPackages                             philiagus/pdostatementbuilder - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. philiagus/pdostatementbuilder

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

philiagus/pdostatementbuilder
=============================

PHP classes to easily build PDO statements

v1.6.0(7mo ago)27.5k↓33.3%1[1 PRs](https://github.com/philiagus/pdostatementbuilder/pulls)MITPHPPHP &gt;=8.1CI passing

Since Jun 8Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/philiagus/pdostatementbuilder)[ Packagist](https://packagist.org/packages/philiagus/pdostatementbuilder)[ RSS](/packages/philiagus-pdostatementbuilder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (20)Used By (0)

philiagus/pdostatementbuilder
=============================

[](#philiaguspdostatementbuilder)

PHP classes to easily build PDO statements.

For all update information please refer to [UPDATE.md](./UPDATE.md).

What is it?
-----------

[](#what-is-it)

A simple way of building complex PDOStatements in a readable way. Want to build an overly complex filter SQL for your project? This is the project to use!

Is it covered?
--------------

[](#is-it-covered)

- 100% Test covered
- Tested in
    - PHP8.1
    - PHP8.2
    - PHP8.3
    - PHP8.4

Why do all this?
----------------

[](#why-do-all-this)

It is very common in database related coding to build statements based on a set of input parameters provided to a repository. This usually looks something like this:

```
class SomeRepository
{
    /**
     * @type \PDO
     */
    private $pdo;

    function getSomething(array $ids, bool $someFilter = false, ?int $exlude = null): array
    {
        if (empty($ids)) {
            return [];
        }
        $statement = "SELECT *
                FROM `table`
                WHERE id IN (?" . str_repeat(',?', count($ids) - 1) . ")";
        $params = array_values($ids);

        if ($someFilter) {
            $statement .= " AND `filter_field` IS NOT NULL AND `filter_field2` = 1";
        }

        if ($exlude !== null) {
            $statement .= ' AND `explude_column` = ?';
            $params[] = $exlude;
        }

        $statement = $this->pdo->prepare($statement);
        $statement->execute($params);

        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }
}
```

Compare this to the following code:

```
class SomeRepository
{
    /**
     * @type \PDO
     */
    private $pdo;

    function getSomething(array $ids, bool $someFilter = false, ?int $exclude = null): array
    {
        if (empty($ids)) {
            return [];
        }

        $builder = new \Philiagus\PDOStatementBuilder\Builder();
        $sql = $builder->build("
            SELECT *
            FROM table
            WHERE id IN ({$builder->in($ids)})
            /* {$builder->if($someFilter)} */
                AND `filter_field` IS NOT NULL AND `filter_field2` = 1
            /* {builder->endif()} */
            /* {builder->if($exclude !== null)} */
                AND `explude_column` = {$builder->value($exclude)}
            /* {$builder->endif()} */
            "
        );

        $statement = $sql->prepare($this->pdo);
        $statement->execute();
        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }
}
```

The code does essentially the same, but the SQL is readable. Additionally, an IDE such as PHPStorm can help you with auto-completion of the SQL.

### Simple Statement building

[](#simple-statement-building)

The Builder also supports a static method to simply build Statements.

```
class SomeRepository
{
    /**
     * @type \PDO
     */
    private $pdo;

    function getSomething(array $ids, bool $someFilter = false, ?int $exclude = null): array
    {
        if (empty($ids)) {
            return [];
        }

        $builder = new \Philiagus\PDOStatementBuilder\Builder();
        $sql = Builder::simple(
            "SELECT * FROM `table` WHERE `id` = :id",
            [':id' => 1]
        );

        $statement = $sql->prepare($this->pdo);
        $statement->execute();
        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }
}
```

The `Builder::simple` method does not only take named parameters (`:id`), but also numeric parameters (for binding with `?` in PDO). You can also simply provide an `Parameter` object (`new Parameter(, , )`) if you want in-place control of the parameter type.

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance72

Regular maintenance activity

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity73

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~114 days

Recently: every ~263 days

Total

18

Last Release

229d ago

PHP version history (3 changes)v1.0.0-RC1PHP &gt;=7.2

v1.2.0PHP &gt;=8.0

v1.4.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/405f18bf2c95e397901d57d857e97799cf5b9a1464eaa4b6af18a8c0780afd1c?d=identicon)[philiagus](/maintainers/philiagus)

---

Top Contributors

[![philiagus](https://avatars.githubusercontent.com/u/12572418?v=4)](https://github.com/philiagus "philiagus (28 commits)")

---

Tags

phpparsesanitize

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/philiagus-pdostatementbuilder/health.svg)

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

###  Alternatives

[surgiie/transformer

A data transforming/formatting package for php.

12724.3k1](/packages/surgiie-transformer)[ondrej-vrto/php-filename-sanitize

Removes all forbidden characters from the file name or path.

1120.6k1](/packages/ondrej-vrto-php-filename-sanitize)

PHPackages © 2026

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