PHPackages                             mcontartesi/nilportugues-sql-query-builder-php - 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. mcontartesi/nilportugues-sql-query-builder-php

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

mcontartesi/nilportugues-sql-query-builder-php
==============================================

An elegant lightweight and efficient SQL QueryInterface BuilderInterface supporting bindings and complicated query generation compatible for PHP 8.1.

04PHPCI failing

Since Feb 8Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mcontartesi/php-sql-query-builder)[ Packagist](https://packagist.org/packages/mcontartesi/nilportugues-sql-query-builder-php)[ RSS](/packages/mcontartesi-nilportugues-sql-query-builder-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Modified SQL Query Builder for PHP 8.1 (original by NilPortugues)

**This is a modified version compatible for PHP 8.1 by Maximiliano Contartesi**

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 nilportugues/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)

```
