PHPackages                             jasny/persist-sql-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. jasny/persist-sql-query

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

jasny/persist-sql-query
=======================

SQL Query builder and parser

v2.0.0(11y ago)33486.0k—7%8[2 issues](https://github.com/jasny/persist-sql-query/issues)4MITPHPPHP &gt;=5.3.0

Since Nov 6Pushed 1y ago6 watchersCompare

[ Source](https://github.com/jasny/persist-sql-query)[ Packagist](https://packagist.org/packages/jasny/persist-sql-query)[ Docs](http://jasny.github.com/dbquery-mysql)[ RSS](/packages/jasny-persist-sql-query/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (5)Used By (4)

[![jasny-banner](https://user-images.githubusercontent.com/100821/62123924-4c501c80-b2c9-11e9-9677-2ebc21d9b713.png)](https://user-images.githubusercontent.com/100821/62123924-4c501c80-b2c9-11e9-9677-2ebc21d9b713.png)

Persist - SQL Query
===================

[](#persist---sql-query)

This library is designed to be the ultimate tool for building, splitting and modifying queries.

Automatic smart quoting helps against SQL injection and problems with reserved keywords.

Supported SQL dialects

- Generic (ANSI standard)
- MySQL
- PostgreSQL *(todo)*
- SQLite *(todo)*

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

[](#installation)

```
composer install jasny/persist-sql-query

```

Examples
--------

[](#examples)

Add `WHERE` conditions and an `OFFSET` to a `SELECT` query

```
use Jasny\Persist\SQL\Query;

$query = (new Query("SELECT * FROM foo LEFT JOIN bar ON foo.bar_id = bar.id WHERE active = 1 LIMIT 25"))
    ->where('type', 'bike')
    ->where('price between ? and ?', [10, 20])
    ->page(3);

echo $query; // SELECT * FROM foo LEFT JOIN bar ON foo.bar_id = bar.id WHERE (active = 1) AND (`type` = 'bike') AND (`price` between 10 and 20) LIMIT 25 OFFSET 50
```

Map fields for an `INSERT INTO ... SELECT ... ON DUPLICATE KEY` query

```
use Jasny\Persist\SQL\Query;

$columns = [
    'ref' => 'ref',
    'man' => 'boy',
    'woman' => 'girl',
    'amount' => 'SUM(z.bucks)'
];

$build = Query::build('mysql');

$select = $build->select()->columns($columns)->from('foo')->innerJoin('z', 'foo.id = z.foo_id')->groupBy('foo.id');
$insert = $build->insert()->into('abc')->columns(array_keys($columns))->set($select)->onDuplicateKeyUpdate();

echo $insert; // INSERT INTO `abc` (`ref`, `man`, `woman`, `amount`)
              //   SELECT `ref` AS `ref`, `boy` AS `man`, `girl` AS `woman`, SUM(`z`.`bucks`) AS `amount` FROM `foo` LEFT JOIN `z` ON `foo`.`id` = `z`.`foo_id` GROUP BY `foo`.id`
              //   ON DUPLICATE KEY UPDATE `ref` = VALUES(`ref`), `man` = VALUES(`man`), `woman` = VALUES(`woman`), `amount` = VALUES(`amount`)
```

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 93.9% 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 ~1453 days

Total

3

Last Release

2035d ago

Major Versions

v1.0.0 → v2.0.02014-08-31

v2.0.0 → v3.0.0-alpha12020-10-21

PHP version history (2 changes)v1.0.0PHP &gt;=5.3.0

v3.0.0-alpha1PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3379a93d51305df325df9045e1a8b205d195e4e8c01312dff53a000ee79002eb?d=identicon)[jasny](/maintainers/jasny)

---

Top Contributors

[![jasny](https://avatars.githubusercontent.com/u/100821?v=4)](https://github.com/jasny "jasny (46 commits)")[![flasica222](https://avatars.githubusercontent.com/u/6462783?v=4)](https://github.com/flasica222 "flasica222 (3 commits)")

---

Tags

databasesqlquerydbquery builder

### Embed Badge

![Health badge](/badges/jasny-persist-sql-query/health.svg)

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

###  Alternatives

[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)[illuminated/db-profiler

Database Profiler for Laravel Web and Console Applications.

168237.4k](/packages/illuminated-db-profiler)[opis/database

A database abstraction layer over PDO, that provides a powerful and intuitive query builder, bundled with an easy to use schema builder

10184.2k3](/packages/opis-database)[atlas/query

Object-oriented query builders and performers for MySQL, Postgres, SQLite, and SQLServer.

41249.0k7](/packages/atlas-query)[bentools/where

PHP7.1 Fluent, immutable SQL query builder. Connectionless, framework-agnostic, no dependency.

125.2k2](/packages/bentools-where)

PHPackages © 2026

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