PHPackages                             reflexive/query - 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. reflexive/query

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

reflexive/query
===============

Somewhat effective SQL query builder

01.0k↓100%PHP

Since Mar 10Pushed 1mo ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

ReflexiveQuery
==============

[](#reflexivequery)

$$ {{∀ x ∈ X : x R x}} $$

---

A lightweight SQL query builder built on top of `reflexive/core`.

The package focuses on producing prepared statements with bound parameters instead of interpolated values.

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

[](#requirements)

- PHP `^8.4`
- `reflexive/core`

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

[](#installation)

```
composer require reflexive/query
```

Main entry points
-----------------

[](#main-entry-points)

The builder is centred around `Reflexive\Query\Composed` and the concrete query types it creates:

- `Select`
- `Insert`
- `Update`
- `Delete`
- `Show`

Helper classes:

- `Condition` and `ConditionGroup` for `WHERE` trees
- `Join` and `Direction` enums
- `CreateTable` for basic DDL
- `Simple` for raw SQL that still uses `PDO::prepare()`

Basic usage
-----------

[](#basic-usage)

```
use Reflexive\Query\Select;
use Reflexive\Query\Condition;
use Reflexive\Query\Direction;

$query = new Query\Select(['u.id', 'u.email'])
	->from(['u' => 'users'])
	->where(Condition::EQUAL('u.active', true))
	->and(Condition::LIKE('u.email', '%@example.com'))
	->order('u.id', Direction::DESC)
	->limit(20)
	->offset(0);

$stmt = $query->prepare($pdo);
$stmt->execute();
$rows = $stmt->fetchAll();
```

`prepare()` calls `PDO::prepare()` and binds all collected parameters with `bindValue()`.

Building conditions
-------------------

[](#building-conditions)

`Condition` extends the core condition factory methods:

```
use Reflexive\Query\Condition;

->where(Condition::EQUAL('users.status', 'published')->and(Condition::IN('users.id', [1, 2, 3])));
```

The generated SQL uses named placeholders:

- scalar values become `:column_0`
- array values become `(:column_0_0, :column_0_1, ...)`
- `NULL` and `NOTNULL` do not bind a value

Nested condition groups are supported through `ConditionGroup`. Passing a Condition chain inside a Condition essentially builds a ConditionGroup.

Supported query features
------------------------

[](#supported-query-features)

`Composed` currently supports:

- selecting explicit columns or falling back to `*`
- table aliases via associative arrays in `from()` / `into()`
- `WHERE` trees
- `INNER`, `LEFT`, `RIGHT`, and `FULL` joins
- `GROUP BY`
- `ORDER BY`
- `LIMIT` and `OFFSET`
- identifier quoting (`$query->quoteNames`)
- optional pretty-printing (`$query->prettify`)

`Insert` and `Update` use `set($column, $value)` to collect assignments.

```
use Reflexive\Query\Insert;

$insert = new Insert()
	->from('users')
	->set('email', 'person@example.com')
	->set('active', 1);
```

Raw queries
-----------

[](#raw-queries)

Use `Simple` when you already have SQL but still want consistent `prepare()` behaviour:

```
use Reflexive\Query\Simple;

$query = new Simple('SELECT COUNT(*) AS c FROM users');
$stmt = $query->prepare($pdo);
$count = Simple::read($stmt, 'c');
```

`Simple::format()` can also turn a statement into a basic HTML table for quick debugging.

DDL helpers
-----------

[](#ddl-helpers)

`CreateTable` builds a MySQL-flavoured `CREATE TABLE` statement:

```
use Reflexive\Query\CreateTable;
use Reflexive\Query\ColumnExtra;

$ddl = new CreateTable('users')
	->addColumn('id', 'BIGINT UNSIGNED', isPrimary: true, extra: ColumnExtra::autoIncrement)
	->addColumn('email', 'VARCHAR(255)', nullable: false);

echo (string) $ddl;
```

It also supports foreign keys through `addConstraint()`, using `ConstraintAction` values for `ON DELETE` / `ON UPDATE`.

Current limitations
-------------------

[](#current-limitations)

- `Call` exists but throws immediately: it is not implemented.
- `CreateTable` emits MySQL-specific SQL (`ENGINE=INNODB`, `utf8mb4`).
- `Show` disables identifier quoting and is meant for database-specific `SHOW ...` statements.
- The package includes some older classes (`Column`, `Constraint`, `Multiple`) that are marked unused or are only lightly integrated.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance62

Regular maintenance activity

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity11

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

Maintainers

![](https://www.gravatar.com/avatar/34f6b38d1f65b58df4307dbdae9c274233181bb737b4098a817d85f19312b63a?d=identicon)[RobinDumontChaponet](/maintainers/RobinDumontChaponet)

---

Top Contributors

[![RobinDumontChaponet](https://avatars.githubusercontent.com/u/9157490?v=4)](https://github.com/RobinDumontChaponet "RobinDumontChaponet (55 commits)")

---

Tags

databasepdophp8queriessqlwork-in-progress

### Embed Badge

![Health badge](/badges/reflexive-query/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M542](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M209](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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