PHPackages                             mstone121/php-object-sql - 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. mstone121/php-object-sql

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

mstone121/php-object-sql
========================

An object-oriented approach to SQL generation

v0.3(5y ago)2740MITPHPPHP &gt;=7.2

Since Apr 22Pushed 3y ago2 watchersCompare

[ Source](https://github.com/mstone121/php-object-sql)[ Packagist](https://packagist.org/packages/mstone121/php-object-sql)[ Docs](https://github.com/mstone121/php-object-sql)[ RSS](/packages/mstone121-php-object-sql/feed)WikiDiscussions main Synced today

READMEChangelog (3)DependenciesVersions (4)Used By (0)

php-object-sql
==============

[](#php-object-sql)

An object-oriented approach to SQL generation in PHP

The goal of this project is to apply the principles of object-oriented programming without the strict requirements and lengthy setup of ORMs to the generation of SQL queries.

Before

```
$query = "SELECT question.id, qr.id, qr.response_label
    FROM questions q
    LEFT JOIN question_responses qr ON qr.question_id = q.id";

if ($questionIds) {
    $query .= "WHERE q.id IN ('" . implode("','", $questionIds) . "')";
}

$query .= " ORDER BY q.id, qr.id";
```

After

```
$query = new QString(
    new QSelect([
        'q.id',
        'qr.id',
        'qr.label'
    ]),
    new QFrom('questions'),
    new QJoinsCollection(
        new QJoinOn(
            'question_responses qr',
            'qr.question_id = q.id',
            'LEFT'
        )
    ),
    new QOrder(['q.id', 'qr.id'])
);

if ($questionIds) {
    $query->addComponent(
        new QWhere(
            new QAnd(
                new QIn('q.id', $questionIds)
            )
        )
    );
}
```

Please note that no checking is performed on strings passed to QComponents. This means you could potentially create a query like so:

```
new QString(
    new QSelect([
        "1; TRUNCATE questions; SELECT *"
    ]),
    new QFrom('questions')
)
```

and it would delete everything in the `questions` table.

This library assumes that you are using it consciously and therefore allows you greater flexibility along with greater responsibility.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

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

Total

3

Last Release

1893d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8356789?v=4)[Matt Stone](/maintainers/mstone121)[@mstone121](https://github.com/mstone121)

---

Top Contributors

[![mstone121](https://avatars.githubusercontent.com/u/8356789?v=4)](https://github.com/mstone121 "mstone121 (3 commits)")

---

Tags

sqlobject oriented

### Embed Badge

![Health badge](/badges/mstone121-php-object-sql/health.svg)

```
[![Health](https://phpackages.com/badges/mstone121-php-object-sql/health.svg)](https://phpackages.com/packages/mstone121-php-object-sql)
```

###  Alternatives

[doctrine/dbal

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

9.7k605.0M6.8k](/packages/doctrine-dbal)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M117](/packages/jdorn-sql-formatter)[doctrine/sql-formatter

a PHP SQL highlighting library

1.9k181.8M112](/packages/doctrine-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k54.9M11.6k](/packages/illuminate-database)[catfan/medoo

The lightweight PHP database framework to accelerate development

5.0k1.6M204](/packages/catfan-medoo)[phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

48252.2M77](/packages/phpmyadmin-sql-parser)

PHPackages © 2026

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