PHPackages                             pthreat/sql-query-builder - 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. pthreat/sql-query-builder

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

pthreat/sql-query-builder
=========================

SQL QueryInterface BuilderInterface supporting bindings and complex query generation.

2.0.0(1y ago)27.2k↓37.3%1[1 issues](https://github.com/pthreat/php-sql-query-builder/issues)[1 PRs](https://github.com/pthreat/php-sql-query-builder/pulls)MITPHPPHP &gt;=8.0

Since Sep 19Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/pthreat/php-sql-query-builder)[ Packagist](https://packagist.org/packages/pthreat/sql-query-builder)[ Docs](https://github.com/pthreat/php-sql-query-builder)[ RSS](/packages/pthreat-sql-query-builder/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (8)Versions (13)Used By (0)

SQL Query Builder
=================

[](#sql-query-builder)

The original project seems to have been abandoned (last modification dating back to 2020)

Main reason I forked this project is to provide support for some bugs that this project has, a big blocker was evaluating NULL as 'NULL' in query values

Here's the link to original repository:

---

An elegant lightweight and efficient SQL Query Builder with fluid interface SQL syntax supporting bindings and complicated query generation. **Works without establishing a connection to the database.**

- [1. Installation](#block1)
- [2. The Builder](#block2)
    - [2.1. Generic Builder](#block2.1)
    - [2.2. MySQL Builder](#block2.2)
    - [2.3. Human Readable Output](#block2.3)
- [3. Building Queries](#block3)
    - [3.1. SELECT Statement](#block3.1)
        - [3.1.1. Basic SELECT statement](#block3.1.1)
        - [3.1.2. Aliased SELECT statement](#block3.1.2)
        - [3.1.3. SELECT with WHERE statement](#block3.1.3)
        - [3.1.4. Complex WHERE conditions](#block3.1.4)
        - [3.1.5. JOIN &amp; LEFT/RIGHT/INNER/CROSS JOIN SELECT statements](#block3.1.5)
        - [3.1.6. COUNT rows](#block3.1.6)
    - [3.2. INSERT Statement](#block3.2)
        - [3.2.1. Basic INSERT statement](#block3.2.1)
    - [3.3. UPDATE Statement](#block3.3)
        - [3.3.1. Basic UPDATE statement](#block3.3.1)
        - [3.3.2. Elaborated UPDATE statement](#block3.3.2)
    - [3.4. DELETE Statement](#block3.4)
        - [3.4.1. Empty table with DELETE statement](#block3.4.1)
        - [3.4.2. Basic DELETE statement](#block3.4.2)
        - [3.4.3. Elaborated DELETE statement](#block3.4.3)
    - [3.5. INTERSECT Statement](#block3.5)
    - [3.6. MINUS Statement](#block3.6)
    - [3.7. UNION Statement](#block3.7)
    - [3.8. UNION ALL Statement](#block3.8)
- [4. Advanced Quering](#block4)
    - [4.1. Filtering using WHERE](#block4.1)
        - [4.1.1. Changing WHERE logical operator](#block4.2)
        - [4.1.2. Writing complicated WHERE conditions](#block4.2)
    - [4.3. Grouping with GROUP BY and HAVING](#block4.3)
        - [4.3.1 Available HAVING operators](#block4.3.1)
    - [4.4. Changing HAVING logical operator](#block4.4)
    - [4.5. Columns as SELECT statements](#block4.5)
    - [4.6. Columns being Values](#block4.6)
    - [4.7. Columns using FUNCTIONS](#block4.7)
- [5. Commenting queries](#block5)
- [6. Quality Code](#block6)
- [7. Author](#block7)
- [8. License](#block8)

1. Installation [↑](#index_block)
---------------------------------

[](#1-installation-)

The recommended way to install the SQL Query Builder is through [Composer](http://getcomposer.org). Run the following command to install it:

```
php composer.phar require pthreat/sql-query-builder
```

2. The Builder [↑](#index_block)
--------------------------------

[](#2-the-builder-)

The SQL Query Builder allows to generate complex SQL queries standard using the `SQL-2003` dialect (default) and the `MySQL` dialect, that extends the `SQL-2003` dialect.

### 2.1. Generic Builder [↑](#index_block)

[](#21-generic-builder-)

The Generic Query Builder is the default builder for this class and writes standard SQL-2003.

**All column aliases are escaped using the `'` sign by default.**

#### Usage:

[](#usage)

```
