Download the PHP package nilportugues/sql-query-builder without Composer

On this page you can find all versions of the php package nilportugues/sql-query-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package sql-query-builder

SQL Query Builder

Build Status Coverage Status Scrutinizer Code Quality SensioLabsInsight Latest Stable Version Total Downloads License Donate

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 ↑

The recommended way to install the SQL Query Builder is through Composer. Run the following command to install it:

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 ↑

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:

Output:

2.2. MySQL Builder ↑

The MySQL Query Builder has its own class, that inherits from the SQL-2003 builder. All columns will be wrapped with the tilde ` sign.

All table and column aliases are escaped using the tilde sign by default.

Usage:

Output:

2.3. Human Readable Output ↑

Both Generic and MySQL Query Builder can write complex SQL queries.

Every developer out there needs at some point revising the output of a complicated query, the SQL Query Builder includes a human-friendly output method, and therefore the writeFormatted method is there to aid the developer when need.

Keep in mind writeFormatted is to be avoided at all cost in production mode as it adds unneeded overhead due to parsing and re-formatting of the generated statement.

Usage:

Output:

More complicated examples can be found in the documentation.

3. Building Queries ↑

3.1. SELECT Statement ↑

3.1.1. Basic SELECT statement ↑

Usage:

Output:

3.1.2. Aliased SELECT statement ↑

Usage:

Output:

3.1.3. SELECT with WHERE statement ↑

Default logical operator for filtering using WHERE conditions is AND.

Usage:

Output:

3.1.4. Complex WHERE conditions ↑

Usage:

Output:

3.1.5. JOIN & LEFT/RIGHT/INNER/CROSS JOIN SELECT statements ↑

Syntax for JOIN, LEFT JOIN, RIGHT JOIN, INNER JOIN, CROSS JOIN work the exactly same way.

Here's an example selecting both table and joined table columns and doing sorting using columns from both the table and the joined table.

Usage:

Output:

3.1.6. COUNT rows ↑

Counting rows comes in 3 possible ways, using the ALL selector *, stating a column or stating a column and its alias.

3.1.6.1. Count using ALL selector

Usage:

Output:

3.1.6.2. Count using column as a selector

Usage:

Output:

3.1.6.3. Count using column as a selector

Usage:

Output:

3.2. INSERT Statement ↑

The INSERT statement is really straightforward.

3.2.1 Basic INSERT statement ↑

Usage:

Output

3.3. UPDATE Statement ↑

The UPDATE statement works just like expected, set the values and the conditions to match the row and you're set.

Examples provided below.

3.3.1 Basic UPDATE statement ↑

Important including the the where statement is critical, or all table rows will be replaced with the provided values if the statement is executed.

Usage:

Output:

3.3.2. Elaborated UPDATE statement ↑

Usage:

Output:

3.4. DELETE Statement ↑

The DELETE statement is used just like UPDATE, but no values are set.

Examples provided below.

3.4.1. Empty table with DELETE statement ↑

Usage:

Output:

3.4.2. Basic DELETE statement ↑

Important including the the where statement is critical, or all table rows will be deleted with the provided values if the statement is executed.

Usage:

Output:

3.4.2. Elaborated DELETE statement ↑

Usage:

Output:

3.5. INTERSECT Statement ↑


INTERSECT is not supported by MySQL. Same results can be achieved by using INNER JOIN statement instead.


The INTERSECT statement is really straightforward.

3.5.1 Basic INTERSECT statement ↑

Usage:

Output

3.6. MINUS Statement ↑


MINUS is not supported by MySQL. Same results can be achieved by using a LEFT JOIN statement in combination with an IS NULL or NOT IN condition instead.


The MINUS statement is really straightforward.

3.6.1 Basic MINUS statement ↑

Usage:

Output

3.7. UNION Statement ↑

The UNION statement is really straightforward.

3.7.1 Basic UNION statement ↑

Usage:

Output

3.8. UNION ALL Statement ↑

The UNION ALL statement is really straightforward.

3.8.1 Basic UNION ALL statement ↑

Usage:

Output

4. Advanced Quering ↑

4.1. Filtering using WHERE ↑

The following operators are available for filtering using WHERE conditionals:

4.2. Changing WHERE logical operator ↑

WHERE default's operator must be changed passing to the where method the logical operator OR.

Usage:

Output:

4.3. Grouping with GROUP BY and HAVING ↑

Default logical operator for joining more than one HAVING condition is AND.

Usage:

Output:

4.3.1 Available HAVING operators ↑

Same operators used in the WHERE statement are available for HAVING operations.

4.4. Changing HAVING logical operator ↑

HAVING default's operator must be changed passing to the having method the logical operator OR.

Usage:

Output:

4.5. Columns as SELECT statements ↑

Sometimes, a column needs to be set as a column. SQL Query Builder got you covered on this one too! Check the example below.

Usage:

Output:

4.6. Columns being Values ↑

There are time where you need to force the same column structure (eg: UNIONs) even when lacking of a column or value. Forcing column with values gets you covered.

Usage:

Output:

4.7. Columns using FUNCTIONS ↑

Example for MAX function.

Usage:

Output:

Example for CURRENT_TIMESTAMP function.

Usage:

Output:

5. Commenting queries ↑

The query builder allows adding comments to all query methods by using the setComment method.

Some useful use cases examples can be :

Usage:

Output:

6. Quality Code ↑

Testing has been done using PHPUnit and Travis-CI. All code has been tested to be compatible from PHP 5.4 up to PHP 5.6 and HHVM.

To run the test suite, you need Composer:

7. Author ↑

Nil Portugués Calderó

8. License ↑

SQL Query Builder is licensed under the MIT license.


All versions of sql-query-builder with dependencies

PHP Build Version
Package Version
Requires php Version >=5.5
nilportugues/sql-query-formatter Version ~1.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nilportugues/sql-query-builder contains the following files

Loading the files please wait ....