PHPackages                             corneltek/sqlbuilder - 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. corneltek/sqlbuilder

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

corneltek/sqlbuilder
====================

Fast and Powerful SQLBuilder for PHP

4.0.1(4y ago)14662.9k—8.3%22[26 issues](https://github.com/c9s/SQLBuilder/issues)3MITPHP

Since Mar 24Pushed 4y ago11 watchersCompare

[ Source](https://github.com/c9s/SQLBuilder)[ Packagist](https://packagist.org/packages/corneltek/sqlbuilder)[ RSS](/packages/corneltek-sqlbuilder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (54)Used By (3)

SQLBuilder for PHP
==================

[](#sqlbuilder-for-php)

[![Build Status](https://camo.githubusercontent.com/cabe999d7cb128d433f8106cec562f09a456ee6e6de9979a1652a67c21145700/68747470733a2f2f7472617669732d63692e6f72672f6339732f53514c4275696c6465722e7376673f6272616e63683d6d6173746572)](http://travis-ci.org/c9s/SQLBuilder)[![Coverage Status](https://camo.githubusercontent.com/1e2f8073211f846d7d46e1ea9602c3e3e23cdb71616e02ee24054b11f5b7d236/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6339732f53514c4275696c6465722e737667)](https://coveralls.io/r/c9s/SQLBuilder)[![Latest Stable Version](https://camo.githubusercontent.com/9d6304d22578a8010a5ef5856cbd4f496a86adb0f5cc505f0d4bd4a43321d99d/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f73716c6275696c6465722f762f737461626c652e737667)](https://packagist.org/packages/corneltek/sqlbuilder)[![Total Downloads](https://camo.githubusercontent.com/71d2d50ead5e46d900ce08424d461ffbc66a62e10f48f229345ea49ff3d1ea64/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f73716c6275696c6465722f646f776e6c6f6164732e737667)](https://packagist.org/packages/corneltek/sqlbuilder)[![Monthly Downloads](https://camo.githubusercontent.com/521a13b36ad2039013c043ffad9b48c2fa626b53e27c7273e724e6794e6bd219/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f73716c6275696c6465722f642f6d6f6e74686c79)](https://packagist.org/packages/corneltek/sqlbuilder)[![Latest Unstable Version](https://camo.githubusercontent.com/42d50ec1178e45af59d33f1d6bede53bbcb081a1b310de35c4f86884e42ac534/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f73716c6275696c6465722f762f756e737461626c652e737667)](https://packagist.org/packages/corneltek/sqlbuilder)[![License](https://camo.githubusercontent.com/d9694feba7ca51351ce28a12df633adb3a9a069a77c2118746a12aa587d143d8/68747470733a2f2f706f7365722e707567782e6f72672f636f726e656c74656b2f73716c6275696c6465722f6c6963656e73652e737667)](https://packagist.org/packages/corneltek/sqlbuilder)

If you're looking for something that is not an ORM but can generate SQL for you, you just found the right one.

SQLBuilder is not an ORM (Object relational mapping) system, but a toolset that helps you generate cross-platform SQL queries in PHP.

SQLBuilder is a stand-alone library, you can simply install it through composer or just require them (the class files) with your autoloader, and it has no dependencies.

Features
--------

[](#features)

- Simple API, easy to remember.
- Fast &amp; Powerful.
- Custom parameter marker support:
    - Question-mark parameter marker.
    - Named parameter marker.
- Configurable quote handler.
- Zero dependency.

Synopsis
--------

[](#synopsis)

Here is a short example of using Universal SelectQuery

```
use SQLBuilder\ArgumentArray;
use SQLBuilder\Universal\Query\SelectQuery;
use SQLBuilder\Driver\MySQLDriver;
use SQLBuilder\Driver\PgSQLDriver;
use SQLBuilder\Driver\SQLiteDriver;

$mysql = new MySQLDriver;
$args = new ArgumentArray;

$query = new SelectQuery;
$query->select(array('id', 'name', 'phone', 'address','confirmed'))
    ->from('users', 'u')
    ->partitions('u1', 'u2', 'u3')
    ->where()
        ->is('confirmed', true)
        ->in('id', [1,2,3])
    ;
$query
    ->join('posts')
        ->as('p')
        ->on('p.user_id = u.id')
    ;
$query
    ->orderBy('rand()')
    ->orderBy('id', 'DESC')
    ;

$sql = $query->toSql($mysql, $args);

var_dump($sql);
var_dump($args);
```

A More Detailed Description
---------------------------

[](#a-more-detailed-description)

Unlike other SQL utilities, SQLBuilder let you define the quote style and the parameter marker type. there are 2 parameter marker type you can choose:

1. Question mark parameter marker (`?`)
2. Named parameter. (`:id`, `:name`, `:address`, `:p1`)

The above two are supported by PDO directly, and the first one is also supported by `mysqli`, `pgsql` extension.

The API is *dead simple, easy to remember*, you can just define one query, then pass different query driver to the query object to get a different SQL string for your targettting platform.

It also supports cross-platform query generation, there are three types of query (currently): **Universal**, **MySQL**, **PgSQL**. The **Universal** queries are cross-platform, you can use them to create a cross-platform PHP API of your database system, and the supported platforms are: **MySQL**, **PgSQL** and **SQLite**.

Universql Queries:

- CreateDatabaseQuery
- DropDatabaseQuery
- SelectQuery
- InsertQuery
- UpdateQuery
- DeleteQuery
- UnionQuery
- CreateIndexQuery
- DropIndexQuery

To see the implementation details, you can check the source code inside **Universal** namespace:

MySQL Queries:

- CreateUserQuery
- DropUserQuery
- GrantQuery
- SetPasswordQuery

For MySQL platform, the implementation is according to the specification of MySQL 5.6.

For PostgreSQL platform, the implementation is according to the specification of PostgreSQL 9.2.

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

[](#installation)

### Install through Composer

[](#install-through-composer)

```
composer require corneltek/sqlbuilder

```

Getting Started
---------------

[](#getting-started)

[Documentation](https://github.com/c9s/SQLBuilder/wiki)

Development
-----------

[](#development)

```
composer install

```

Copy the `phpunit.xml` file for your local configuration:

```
phpunit -c your-phpunit.xml tests
```

Contribution
------------

[](#contribution)

To test with mysql database:

```
mysql -uroot -p
CREATE DATABASE sqlbuilder CHARSET utf8;
GRANT ALL PRIVILEGES ON sqlbuilder.* TO 'testing'@'localhost' identified by '';

--- or use this to remove password for testing account
SET PASSWORD FOR testing@localhost=PASSWORD('');

```

To test with pgsql database:

```
sudo -u postgres createdb sqlbuilder

```

Reference
---------

[](#reference)

-
-
-

Author
------

[](#author)

Yo-An Lin (c9s)

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance16

Infrequent updates — may be unmaintained

Popularity47

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 99.1% 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 ~60 days

Recently: every ~491 days

Total

53

Last Release

1657d ago

Major Versions

1.5.x-dev → 2.0-beta2015-01-05

2.8.9 → 3.0.02016-06-10

3.2.x-dev → 4.0.02017-05-10

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cc34cde233b660869ff329ed8e20df611f75dfb61aab3e30889ac153d3e5e61?d=identicon)[c9s](/maintainers/c9s)

---

Top Contributors

[![c9s](https://avatars.githubusercontent.com/u/50894?v=4)](https://github.com/c9s "c9s (1025 commits)")[![kbinani](https://avatars.githubusercontent.com/u/1030301?v=4)](https://github.com/kbinani "kbinani (2 commits)")[![iggyvolz](https://avatars.githubusercontent.com/u/2197376?v=4)](https://github.com/iggyvolz "iggyvolz (2 commits)")[![bubach](https://avatars.githubusercontent.com/u/2346370?v=4)](https://github.com/bubach "bubach (2 commits)")[![joushx](https://avatars.githubusercontent.com/u/832178?v=4)](https://github.com/joushx "joushx (1 commits)")[![krichprollsch](https://avatars.githubusercontent.com/u/562696?v=4)](https://github.com/krichprollsch "krichprollsch (1 commits)")[![SmetDenis](https://avatars.githubusercontent.com/u/1118678?v=4)](https://github.com/SmetDenis "SmetDenis (1 commits)")

---

Tags

databasemysqlpgsqlphpsql-buildersql-query

### Embed Badge

![Health badge](/badges/corneltek-sqlbuilder/health.svg)

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

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90440.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)[wildside/userstamps

Laravel Userstamps provides an Eloquent trait which automatically maintains `created\_by` and `updated\_by` columns on your model, populated by the currently authenticated user in your application.

7511.7M13](/packages/wildside-userstamps)

PHPackages © 2026

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