QueryBuilder
class QueryBuilder implements JsonSerializable (View source)
Properties
| protected ?string | $table | The table name |
|
| protected ?string | $select | Select statement collector |
|
| protected ?string | $where | Where statement collector |
|
| protected array | $where_data_binding | The data binding information |
|
| protected ?string | $join | Join statement collector |
|
| protected ?string | $limit | Limit statement collector |
|
| protected ?string | $group | Group statement collector |
|
| protected ?string | $having | Having statement collector |
|
| protected ?string | $order | Order By statement collector |
|
| protected ?string | $as | Define the table as |
|
| protected PDO | $connection | The PDO instance |
|
| protected bool | $first | Define whether to retrieve information from the list |
|
| protected string | $prefix | The table prefix |
|
| protected string | $adapter | The adapter name |
Methods
QueryBuilder Constructor
Get the connection adapter name
Create the table as
Add where clause into the request
Add orWhere clause into the request
orWhere, add a condition of type:
Add where clause into the request
Formats the select request
Returns the name of the table.
Change the table's name
Where clause with comparison in << is null >>
Where clause with comparison in <
WHERE column NOT BETWEEN '' AND ''
Where clause with comparison <
Where clause with <
Where clause with <
Join clause
Returns the prefix.
Modify the prefix
Left Join clause
Right Join clause
On, if chained with itself must add an << and >> before, otherwise if chained with "orOn" who add a "before"
Clause On, followed by a combination by a comparator <
Clause Group By
clause having, is used with a groupBy
Clause Order By
Max
Min
Avg
Sum
Get the last record
Count
Get the first record
Take = Limit
Get make, only on the select request If the first selection mode is not active
Add select column.
Jump = Offset
Update action
Remove simplified stream from delete.
Delete row on table
Increment column
Decrement column
Allows a query with the DISTINCT clause
Truncate table
InsertAndGetLastId action launches the insert and lastInsertId actions
Insert
Drop, remove the table
Paginate, make pagination system
Check if a value already exists in the DB
Turn back the id of the last insertion
JsonSerialize implementation
Define the data to associate
__toString
Transformation automatically the result to JSON
Details
__construct(string $table, AbstractConnection|PDO $connection)
QueryBuilder Constructor
string
getAdapterName()
Get the connection adapter name
PDO
getPdo()
Get the connection
QueryBuilder
as(string $as)
Create the table as
QueryBuilder
whereRaw(string $where)
Add where clause into the request
WHERE column1 $comparator $value|column
QueryBuilder
orWhereRaw(string $where)
Add orWhere clause into the request
WHERE column1 $comparator $value|column
QueryBuilder
orWhere(string $column, mixed $comparator = '=', mixed $value = null)
orWhere, add a condition of type:
[where column = value or column = value]
QueryBuilder
where(string $column, mixed $comparator = '=', mixed $value = null, string $boolean = 'and')
Add where clause into the request
WHERE column1 $comparator $value|column
string
toSql()
Formats the select request
string
getTable()
Returns the name of the table.
QueryBuilder
setTable(string $table)
Change the table's name
QueryBuilder
whereNull(string $column, string $boolean = 'and')
Where clause with comparison in << is null >>
WHERE column IS NULL
QueryBuilder
whereNotNull($column, string $boolean = 'and')
Where clause with comparison in <
WHERE column NOT NULL
QueryBuilder
whereNotBetween(string $column, array $range)
WHERE column NOT BETWEEN '' AND ''
QueryBuilder
whereBetween(string $column, array $range, string $boolean = 'and')
Where clause with comparison <
WHERE column BETWEEN '' AND ''
QueryBuilder
whereNotIn(string $column, array $range)
Where clause with <
QueryBuilder
whereIn(string $column, array $range, string $boolean = 'and')
Where clause with <
QueryBuilder
join(string $table, string $first, mixed $comparator = '=', string|null $second = null)
Join clause
string
getPrefix()
Returns the prefix.
QueryBuilder
setPrefix(string $prefix)
Modify the prefix
QueryBuilder
leftJoin(string $table, string $first, mixed $comparator = '=', string|null $second = null)
Left Join clause
QueryBuilder
rightJoin(string $table, string $first, mixed $comparator = '=', string|null $second = null)
Right Join clause
QueryBuilder
andOn(string $first, mixed $comparator = '=', string $second = null)
On, if chained with itself must add an << and >> before, otherwise if chained with "orOn" who add a "before"
QueryBuilder
orOn(string $first, mixed $comparator = '=', string $second = null)
Clause On, followed by a combination by a comparator <
QueryBuilder
group(string $column)
deprecated
deprecated
Clause Group By
QueryBuilder
groupBy(string $column)
Clause Group By
QueryBuilder
having(string $column, mixed $comparator = '=', mixed $value = null, string $boolean = 'and')
clause having, is used with a groupBy
QueryBuilder
orderBy(string $column, string $type = 'asc')
Clause Order By
int|float
max(string $column)
Max
int|float
min(string $column)
Min
int|float
avg(string $column)
Avg
int|float
sum(string $column)
Sum
object|null
last()
Get the last record
int
count(string $column = '*')
Count
object|null
first()
Get the first record
QueryBuilder
take(int $limit)
Take = Limit
array|object|null
get(array $columns = [])
Get make, only on the select request If the first selection mode is not active
QueryBuilder
select(array $select = ['*'])
Add select column.
SELECT $column | SELECT column1, column2, ...
QueryBuilder
jump(int $offset = 0)
Jump = Offset
int
update(array $data = [])
Update action
int
remove(string $column, mixed $comparator = '=', string $value = null)
Remove simplified stream from delete.
int
delete()
Delete row on table
int
increment(string $column, int $step = 1)
Increment column
int
decrement(string $column, int $step = 1)
Decrement column
QueryBuilder
distinct(string $column)
Allows a query with the DISTINCT clause
This method modifies the SELECT statement to include the DISTINCT keyword, ensuring that the results returned are unique for the specified column.
bool
truncate()
Truncate table
This method will remove all rows from the table without logging the individual row deletions. It is faster than the DELETE statement because it does not generate individual row delete actions. However, it cannot be rolled back if the database is not in a transaction.
string|int|bool
insertAndGetLastId(array $values)
InsertAndGetLastId action launches the insert and lastInsertId actions
int
insert(array $values)
Insert
The data to be inserted into the database.
bool
drop()
Drop, remove the table
Pagination
paginate(int $number_of_page, int $current = 0, int|null $chunk = null)
Paginate, make pagination system
bool
exists(string|null $column = null, mixed $value = null)
Check if a value already exists in the DB
string
getLastInsertId(string|null $name = null)
Turn back the id of the last insertion
mixed
jsonSerialize()
JsonSerialize implementation
void
setWhereDataBinding(array $data_binding)
Define the data to associate
string
__toString()
__toString
string
toJson(int $option = 0)
Transformation automatically the result to JSON