PHPackages                             markjaquith/wherewithal - 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. markjaquith/wherewithal

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

markjaquith/wherewithal
=======================

Given constraints, parses a string of conditions into a valid MySQL WHERE clause

0.1.1(5y ago)15[1 issues](https://github.com/markjaquith/Wherewithal/issues)MITPHPPHP ^7.4

Since Mar 9Pushed 5y ago1 watchersCompare

[ Source](https://github.com/markjaquith/Wherewithal)[ Packagist](https://packagist.org/packages/markjaquith/wherewithal)[ RSS](/packages/markjaquith-wherewithal/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (4)Used By (0)

Wherewithal
===========

[](#wherewithal)

Given constraints, parses a string of conditions into a valid MySQL WHERE clause

[![Tests](https://github.com/markjaquith/Wherewithal/actions/workflows/ci.yml/badge.svg)](https://github.com/markjaquith/Wherewithal/actions/workflows/ci.yml/badge.svg)

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

[](#installation)

`composer require markjaquith/wherewithal`

Usage
-----

[](#usage)

```
use MarkJaquith\Wherewithal\{Parser, Config};

$config = (new Config)
	->addOperators('', '=', '=', '/') // Or add a subset.
	->addColumn('column_name', 'column_alias1', 'column_alias2')
	->addColumn('quantity')
	->addColumn('price', 'cost');

$parser = new Parser($config);

$structure = $parser->parse('quantity > 5 and (price < 3.00 or column_alias2 = 10'));

$structure->toString();
/*
  string(57) "quantity > ? and ( price < ? or price / column_name = ? )"
*/

$structure->getBindings()]);
/*
  array(3) {
    [0]=>
    string(1) "5"
    [1]=>
    string(4) "3.00"
    [2]=>
    string(2) "10"
  }
*/
```

You can also map simple column names to complex expressions like so:

```
$structure->mapColumns(function($col) {
	return [
		'column_name' => '`some_long_table_name`.`long_column_name`',
	]($col) ?? $col;
})->toString();
/*
	string(92) "(`some_long_table_name`.`long_column_name`) > ? and ( price < ? or price / column_name = ? )"
*/
```

Columns that you don't put in the config will be assumed to be values. Values always use the placeholder token `?`.

You should combine the resulting `WHERE` (or `HAVING`) clause using your database layer. Here's how you'd do it in Laravel:

```
$orders = DB::table('orders')
	->whereRaw($structure->toString(), $structure->getBindings())
  ->get();
```

###  Health Score

16

—

LowBetter than 4% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

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

Total

2

Last Release

1941d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/353790?v=4)[Mark Jaquith](/maintainers/markjaquith)[@markjaquith](https://github.com/markjaquith)

---

Top Contributors

[![markjaquith](https://avatars.githubusercontent.com/u/353790?v=4)](https://github.com/markjaquith "markjaquith (37 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/markjaquith-wherewithal/health.svg)

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

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

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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