Download the PHP package dmitryproa/php-advanced-querying without Composer
On this page you can find all versions of the php package dmitryproa/php-advanced-querying. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dmitryproa/php-advanced-querying
More information about dmitryproa/php-advanced-querying
Files in dmitryproa/php-advanced-querying
Package php-advanced-querying
Short Description A PHP library for building and formatting complex SQL queries
License MIT
Informations about the package php-advanced-querying
PHP Advanced Querying
A PHP library for building and formatting complex SQL queries. Tested on PHP 7.1 and PHP 7.4.
Example
Result:
Table of contents
- 1. Installation
- 2. Syntax
- 2.1 Builder
- 2.2 Table
- 2.3 Select columns
- 2.4 Update values
- 2.5 Insert fields
- 2.6 Insert values
- 2.7 Expressions
- 2.7.1 Column expression
- 2.7.2 Literal expression
- 2.7.3 Select expression
- 2.7.4 Function expression
- 2.8 Statements
- 2.8.1 Conditional (WHERE) statements
- 2.8.2 JOIN statements
- 2.8.3 SELECT statement
- 2.8.4 UPDATE statement
- 2.8.5 INSERT and REPLACE statements
- 2.8.6 INSERT... SELECT and REPLACE... SELECT statements
1. Installation ↑
The recommended way to install this library is through Composer. Run the following command to install it:
composer require dmitryproa/php-advanced-querying
2. Syntax ↑
2.1 Builder ↑
Class QueryBuilder
provides the following methods for building a statement:
2.2 Table ↑
Table
specified as follows:
2.3 Select columns ↑
Select columns are pairs of alias (optional) and expression, and defined as associative array:
2.4 Update values ↑
Update values are pairs of a column and an expression, and defined the same way as columns:
2.5 Insert fields ↑
Insert fields are plain strings:
2.6 Insert values ↑
One- or two-dimensional array of literals:
2.7 Expressions ↑
2.7.1 Column expression ↑
2.7.2 Literal expression ↑
2.7.3 Select expression ↑
2.7.4 Function expression ↑
There are several pre-defined functions:
2.8 Statements ↑
Every statement have a setTable($table)
method.
2.8.1 Conditional (WHERE) statements ↑
Some statements (such as SELECT, UPDATE and DELETE) can specify WHERE conditions:
Conditions can also be defined using helper functions: true()
, false()
, eq()
, notEq()
, greater()
, greaterEquals()
, less()
, lessEquals()
, like()
, notLike()
, isNull()
, isNotNull()
, in()
, notIn()
, and_()
and or_()
.
For example:
Conditions can be used as expressions:
2.8.2 JOIN statements ↑
Select
and Update
statements have a join()
method:
Available join types: Join::OUTER
, Join::INNER
, Join::LEFT
, Join::RIGHT
.
2.8.3 SELECT statement ↑
Select
statement have following methods:
Select
statement can use another Select
as table, for example:
UNION SELECT
statement can be made by calling an unionSelect()
functions, which returns a new SELECT
.
For example:
2.8.4 UPDATE statement ↑
Update
statement have the following methods:
2.8.5 INSERT and REPLACE statements ↑
These statements have the following methods:
INSERT
statement also have the following methods:
2.8.6 INSERT... SELECT and REPLACE... SELECT statements ↑
These statements have the following methods:
InsertSelect
statement also have ignore()
and onDuplicateKeyUpdate()
methods.