PHPackages                             baddum/sql418 - 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. baddum/sql418

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

baddum/sql418
=============

A library for extensible SQL requests

v1.2.0(11y ago)123MITPHPPHP &gt;=5.4.0

Since Jan 27Pushed 11y ago1 watchersCompare

[ Source](https://github.com/Baddum/SQL418)[ Packagist](https://packagist.org/packages/baddum/sql418)[ Docs](https://github.com/Baddum/SQL418)[ RSS](/packages/baddum-sql418/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (6)Used By (0)

SQL418
======

[](#sql418)

[![Latest Stable Version](https://camo.githubusercontent.com/2ee49a604f0a2366fa45ff37d121b6cdc094dc6dc77f91281f32343f486061ec/68747470733a2f2f706f7365722e707567782e6f72672f62616464756d2f73716c3431382f762f737461626c652e737667)](https://github.com/Baddum/SQL418)[![Build Status](https://camo.githubusercontent.com/b0fe7b27e36bea27e5a768cd6920c23b6a664b85524032fa96c3dd3189980f67/68747470733a2f2f7472617669732d63692e6f72672f42616464756d2f53514c3431382e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/Baddum/SQL418)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/cfa9fbd4bc379bd508097cc894524f24c6e83c295d517205e88dc48050bea0fd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f42616464756d2f53514c3431382f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Baddum/SQL418/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/065236114488ac31e316d25c5700601e39b490ab640e16307c3eb88a249de959/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f42616464756d2f53514c3431382f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Baddum/SQL418/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/0a6f1600d420428196db61aeeb6f183dff67de3d1c712b09939c83f09d7aa2b4/68747470733a2f2f706f7365722e707567782e6f72672f62616464756d2f73716c3431382f646f776e6c6f6164732e737667)](https://packagist.org/packages/baddum/sql418)[![License](https://camo.githubusercontent.com/6284ff2e5b0c28b25f67c0b64811511ecaf0d47a85eab0fbd832ff2d4003e59b/68747470733a2f2f706f7365722e707567782e6f72672f62616464756d2f73716c3431382f6c6963656e73652e737667)](http://opensource.org/licenses/MIT)

`SQL418` is a small PHP library for extensible SQL requests.

This library allows you to modify an existing SQL statement, by overriding some parts of it.

1. [Features](#features)
2. [Use cases](#use-cases)
3. [How to Install](#how-to-install)
4. [How to Contribute](#how-to-contribute)
5. [Author &amp; Community](#author--community)

Features
--------

[](#features)

Use the `extend()` method to complete a request.
An example to add a `WHERE` clause to a `SELECT` request:

```
$request = new Baddum\SQL418\Request('SELECT * from table');
echo $request->extend('WHERE id = 39');
// SELECT * FROM table WHERE id = 39;
```

You can override a defined part of a request.
An example to change the selected fields:

```
echo $request->extend('SELECT name');
// SELECT name FROM table WHERE id = 39;
```

Use the `&` keyword to extend a part of a request.
An example to add a field to select:

```
echo $request->extend('SELECT &, id');
// SELECT name, id FROM table WHERE id = 39;
```

You can change the type of a request.
An example to change a `SELECT` request to a `DELETE` one:

```
echo $request->extend('DELETE');
// DELETE FROM table WHERE id = 39;
```

You can also use all the features together:

```
$sql->extend('UPDATE SET name = "Albert" WHERE & AND right  admin"');
echo $sql;
// UPDATE table SET name = "Albert" WHERE id = 39 AND right  admin;
```

Use cases
---------

[](#use-cases)

### Use case: DRYer requests

[](#use-case-dryer-requests)

In the following example, the `fetchById` and `deleteById` requests share a common pattern:

```
class UserModel {
  protected $SQLFetchById = 'SELECT * from user WHERE user.id=?';
  protected $SQLDeleteById = '';
  public function __construct() {
    $request = new Request($this->SQLFetchById);
    $this->SQLDeleteById = $request->extend('DELETE');
  }
}
```

### Use case: extensible applications

[](#use-case-extensible-applications)

In the following example, we extend the `UserModel` to do a soft delete:

```
class UserModelSoftDelete extends UserModel {
  public function __construct() {
    $request = new Request($this->SQLFetchById);
    $this->SQLFetchById = $request->extend('WHERE & AND user.deleted = 0');
    $this->SQLDeleteById = $request->extend('UPDATE & SET user.deleted = 1');
  }
}
```

How to Install
--------------

[](#how-to-install)

This library package requires `PHP 5.4` or later.
Install [Composer](http://getcomposer.org/doc/01-basic-usage.md#installation) and run the following command to get the latest version:

```
composer require baddum/sql418:~1.2
```

How to Contribute
-----------------

[](#how-to-contribute)

1. [Star](https://github.com/Baddum/SQL418/stargazers) the project!
2. Tweet and blog about SQL418 and [Let me know](https://twitter.com/iamtzi) about it.
3. [Report a bug](https://github.com/Baddum/SQL418/issues/new) that you find
4. Pull requests are highly appreciated. Please review the [guidelines for contributing](https://github.com/Baddum/SQL418/blob/master/CONTRIBUTING.md) to go further.

Author &amp; Community
----------------------

[](#author--community)

SQL418 is under [MIT License](http://opensource.org/licenses/MIT).
It was created &amp; is maintained by [Thomas ZILLIOX](http://tzi.fr).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

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

Total

5

Last Release

4127d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1dd01ef560c81cff6d288330b80a88f6728cf4f2b6fc6f5ab19dacde2f1cda06?d=identicon)[tzi](/maintainers/tzi)

---

Top Contributors

[![tzi](https://avatars.githubusercontent.com/u/415891?v=4)](https://github.com/tzi "tzi (39 commits)")

---

Tags

sqlpdo

### Embed Badge

![Health badge](/badges/baddum-sql418/health.svg)

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

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[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)[paragonie/easydb

Easy-to-use database abstraction

744273.4k23](/packages/paragonie-easydb)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[ezsql/ezsql

Advance database access library. Make interacting with a database ridiculously easy. An universal interchangeable CRUD system.

86946.7k](/packages/ezsql-ezsql)

PHPackages © 2026

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