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.2kPHP

Since May 27Pushed 2w ago1 watchersCompare

[ Source](https://github.com/RobinDumontChaponet/ReflexiveQuery)[ Packagist](https://packagist.org/packages/reflexive/query)[ RSS](/packages/reflexive-query/feed)WikiDiscussions master Synced 3w 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

26

—

LowBetter than 41% of packages

Maintenance63

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://avatars.githubusercontent.com/u/9157490?v=4)[Robin Dumont-Chaponet](/maintainers/RobinDumontChaponet)[@RobinDumontChaponet](https://github.com/RobinDumontChaponet)

---

Top Contributors

[![RobinDumontChaponet](https://avatars.githubusercontent.com/u/9157490?v=4)](https://github.com/RobinDumontChaponet "RobinDumontChaponet (62 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

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k116.5M113](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[yemenopensource/filament-excel

This package useful for importing excel files into models.

194.2k](/packages/yemenopensource-filament-excel)

PHPackages © 2026

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