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

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

masterweber/sqlbuilder
======================

Simple SQL query constructor.

v1.3.1(5y ago)311MITPHPPHP &gt;=7.4

Since Jan 6Pushed 5y ago1 watchersCompare

[ Source](https://github.com/masterWeber/sqlbuilder)[ Packagist](https://packagist.org/packages/masterweber/sqlbuilder)[ RSS](/packages/masterweber-sqlbuilder/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (4)Dependencies (1)Versions (7)Used By (0)

SQLBuilder
==========

[](#sqlbuilder)

[![Build Status](https://camo.githubusercontent.com/b6347f510c684f234b7262d3a6846f9e2f25785ba80ba81e6a4eeba888c4e768/68747470733a2f2f7472617669732d63692e6f72672f6d617374657257656265722f73716c6275696c6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/masterWeber/sqlbuilder)[![Coverage Status](https://camo.githubusercontent.com/a00ebdab06078644448c26c2ba5348841ad6ba3a6d1bcfcd8bb83431c47dd901/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d617374657257656265722f73716c6275696c6465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/masterWeber/sqlbuilder?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/533513790f7deb55db763b2964fe4551e5faecff5e2b488cd49966d6dc0b7b84/68747470733a2f2f706f7365722e707567782e6f72672f6d617374657277656265722f73716c6275696c6465722f76)](https://packagist.org/packages/masterweber/sqlbuilder)[![Total Downloads](https://camo.githubusercontent.com/9ef3f59bff65b66e0c93a58d7c7c5469f32d1a3ad505a24c97a0df728c3e61bf/68747470733a2f2f706f7365722e707567782e6f72672f6d617374657277656265722f73716c6275696c6465722f646f776e6c6f616473)](https://packagist.org/packages/masterweber/sqlbuilder)[![Latest Unstable Version](https://camo.githubusercontent.com/6990806cf6d37f8a299a3319b26a62b67934f1f11812bdb82166a1b86c45cda2/68747470733a2f2f706f7365722e707567782e6f72672f6d617374657277656265722f73716c6275696c6465722f762f756e737461626c65)](https://packagist.org/packages/masterweber/sqlbuilder)[![License](https://camo.githubusercontent.com/942bce096273fad7be86cca9300162d4ddb716fe88cc3372a5e017c835db4bb4/68747470733a2f2f706f7365722e707567782e6f72672f6d617374657277656265722f73716c6275696c6465722f6c6963656e7365)](https://packagist.org/packages/masterweber/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 system, but a toolset that helps you generate SQL queries in PHP.

Features
--------

[](#features)

- Simple API, easy to remember.
- Fast.
- Zero dependency.

Synopsis
--------

[](#synopsis)

Here is a short example of using

```
use SQLBuilder\SQLBuilder;
use SQLBuilder\Expression\Column;
use SQLBuilder\Clause\OrderBy;

$builder = new SQLBuilder();

$sql = $builder->select(['t1.column' => 'col1','t2.column' => 'col2'])
  ->from(['table1' => 't1'])
  ->join(['table2' => 't2'])
  ->right()
  ->on()
  ->equal('col1', Column::from('t2.col3'))
  ->where()
  ->isNotNull('col1')
  ->orderBy('col2', OrderBy::DESC)
  ->limit(10)
  ->offset(10);
```

```
  SELECT `t1`.`column` AS `col1`, `t2`.`column` AS `col2`
  FROM `table1` AS `t1` RIGHT JOIN `table2` AS `t2` ON (`col1` = `t2`.`col3`)
  WHERE `col1` IS NOT NULL ORDER BY `col2` DESC LIMIT 10 OFFSET 10
```

CRUD Query Examples
-------------------

[](#crud-query-examples)

### Insert

[](#insert)

```
use SQLBuilder\SQLBuilder;

$sqlBuilder = new SqlBuilder();

$sql = $sqlBuilder->insertInto('table_name')->values([5, 2]);
```

```
INSERT INTO `table_name` VALUES (5, 2)
```

Insert Data Only in Specified Columns

```
use SQLBuilder\SQLBuilder;

$sqlBuilder = new SqlBuilder();

$sql = $sqlBuilder->insertInto('table_name')
  ->columns(['first', 'second'])
  ->values([5, 2]);
```

```
INSERT INTO `table_name` (`first`, `second`) VALUES (5, 2)
```

Insert default data

```
use SQLBuilder\SQLBuilder;

$sqlBuilder = new SqlBuilder();

$sql = $sqlBuilder->insertInto('table_name')->default();
```

```
INSERT INTO `table_name` DEFAULT VALUES
```

### Select

[](#select)

```
use SQLBuilder\SQLBuilder;

$sqlBuilder = new SqlBuilder();

$sql = $sqlBuilder->select()
  ->from('table_name')
  ->where()
  ->equal('column', 5)
  ->limit(17)
  ->offset(10);
```

```
SELECT * FROM `table_name` WHERE `column` = 5 LIMIT 10 OFFSET 10
```

With JOIN

```
use SQLBuilder\SQLBuilder;
use SQLBuilder\Expression\Column;
use SQLBuilder\Clause\OrderBy;

$sqlBuilder = new SqlBuilder();

$sql = $sqlBuilder->select(['t1.column' => 'col1','t2.column' => 'col2'])
  ->distinct()
  ->from(['table1' => 't1'])
  ->join(['table2' => 't2'])
  ->right()
  ->on()
  ->equal('col1', Column::from('t2.col3'))
  ->where()
  ->isNotNull('col1')
  ->orderBy('col2', OrderBy::DESC)
  ->limit(12745);
```

```
SELECT DISTINCT `t1`.`column` AS `col1`, `t2`.`column` AS `col2`
FROM `table1` AS `t1` RIGHT JOIN `table2` AS `t2` ON (`col1` = `t2`.`col3`)
WHERE `col1` IS NOT NULL ORDER BY `col2` DESC LIMIT 12745
```

### Update

[](#update)

```
use SQLBuilder\SQLBuilder;

$sqlBuilder = new SqlBuilder();

$sql = $sqlBuilder->update('table_name')
  ->set(['col1' => 1, 'date' => '2000-01-01'])
  ->where(['id' => 5])
  ->limit(1);
```

```
UPDATE `table_name` SET `col1` = 1, `date` = '2000-01-01' WHERE `id` = 5 LIMIT 1
```

### Delete

[](#delete)

```
use SQLBuilder\SQLBuilder;

$sqlBuilder = new SqlBuilder();

$sql = $sqlBuilder->delete()
  ->from('table_name')
  ->where()
  ->equal('col1', 2)
  ->and()
  ->equal('col2', 23)
  ->limit(3);
```

```
DELETE FROM `table_name` WHERE `col1` = 2 AND `col2` = 23 LIMIT 3
```

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

[](#installation)

### Install through Composer

[](#install-through-composer)

```
composer require masterweber/sqlbuilder

```

Author
------

[](#author)

masterWeber

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

6

Last Release

1956d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/34d2886f50d9f510a3dcfeac56044b9d51751f1708df324cff83d3b57cf75968?d=identicon)[masterWeber](/maintainers/masterWeber)

---

Top Contributors

[![masterWeber](https://avatars.githubusercontent.com/u/47494224?v=4)](https://github.com/masterWeber "masterWeber (85 commits)")

---

Tags

sqlsql-build

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[jdorn/sql-formatter

a PHP SQL highlighting library

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

a PHP SQL highlighting library

1.9k166.0M85](/packages/doctrine-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[catfan/medoo

The lightweight PHP database framework to accelerate development

4.9k1.5M194](/packages/catfan-medoo)[phpmyadmin/sql-parser

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

47950.4M55](/packages/phpmyadmin-sql-parser)

PHPackages © 2026

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