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

__construct(string $table, AbstractConnection|PDO $connection)

QueryBuilder Constructor

string
getAdapterName()

Get the connection adapter name

PDO
getPdo()

Get the connection

as(string $as)

Create the table as

whereRaw(string $where)

Add where clause into the request

orWhereRaw(string $where)

Add orWhere clause into the request

orWhere(string $column, mixed $comparator = '=', mixed $value = null)

orWhere, add a condition of type:

where(string $column, mixed $comparator = '=', mixed $value = null, string $boolean = 'and')

Add where clause into the request

string
toSql()

Formats the select request

string
getTable()

Returns the name of the table.

setTable(string $table)

Change the table's name

whereNull(string $column, string $boolean = 'and')

Where clause with comparison in << is null >>

whereNotNull($column, string $boolean = 'and')

Where clause with comparison in <>

whereNotBetween(string $column, array $range)

WHERE column NOT BETWEEN '' AND ''

whereBetween(string $column, array $range, string $boolean = 'and')

Where clause with comparison <>

whereNotIn(string $column, array $range)

Where clause with <> comparison

whereIn(string $column, array $range, string $boolean = 'and')

Where clause with <> comparison

join(string $table, string $first, mixed $comparator = '=', string|null $second = null)

Join clause

string
getPrefix()

Returns the prefix.

setPrefix(string $prefix)

Modify the prefix

leftJoin(string $table, string $first, mixed $comparator = '=', string|null $second = null)

Left Join clause

rightJoin(string $table, string $first, mixed $comparator = '=', string|null $second = null)

Right Join clause

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"

orOn(string $first, mixed $comparator = '=', string $second = null)

Clause On, followed by a combination by a comparator <> The user has to do an "on()" before using the "orOn"

group(string $column) deprecated

Clause Group By

groupBy(string $column)

Clause Group By

having(string $column, mixed $comparator = '=', mixed $value = null, string $boolean = 'and')

clause having, is used with a groupBy

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

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

select(array $select = ['*'])

Add select column.

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

distinct(string $column)

Allows a query with the DISTINCT clause

bool
truncate()

Truncate table

string|int|bool
insertAndGetLastId(array $values)

InsertAndGetLastId action launches the insert and lastInsertId actions

int
insert(array $values)

Insert

bool
drop()

Drop, remove the table

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

Details

__construct(string $table, AbstractConnection|PDO $connection)

QueryBuilder Constructor

Parameters

string $table
AbstractConnection|PDO $connection

string getAdapterName()

Get the connection adapter name

Return Value

string

PDO getPdo()

Get the connection

Return Value

PDO

QueryBuilder as(string $as)

Create the table as

Parameters

string $as

Return Value

QueryBuilder

QueryBuilder whereRaw(string $where)

Add where clause into the request

WHERE column1 $comparator $value|column

Parameters

string $where

Return Value

QueryBuilder

QueryBuilder orWhereRaw(string $where)

Add orWhere clause into the request

WHERE column1 $comparator $value|column

Parameters

string $where

Return Value

QueryBuilder

QueryBuilder orWhere(string $column, mixed $comparator = '=', mixed $value = null)

orWhere, add a condition of type:

[where column = value or column = value]

Parameters

string $column
mixed $comparator
mixed $value

Return Value

QueryBuilder

Exceptions

QueryBuilderException

QueryBuilder where(string $column, mixed $comparator = '=', mixed $value = null, string $boolean = 'and')

Add where clause into the request

WHERE column1 $comparator $value|column

Parameters

string $column
mixed $comparator
mixed $value
string $boolean

Return Value

QueryBuilder

Exceptions

QueryBuilderException

string toSql()

Formats the select request

Return Value

string

string getTable()

Returns the name of the table.

Return Value

string

QueryBuilder setTable(string $table)

Change the table's name

Parameters

string $table

Return Value

QueryBuilder

QueryBuilder whereNull(string $column, string $boolean = 'and')

Where clause with comparison in << is null >>

WHERE column IS NULL

Parameters

string $column
string $boolean

Return Value

QueryBuilder

QueryBuilder whereNotNull($column, string $boolean = 'and')

Where clause with comparison in <>

WHERE column NOT NULL

Parameters

$column
string $boolean

Return Value

QueryBuilder

QueryBuilder whereNotBetween(string $column, array $range)

WHERE column NOT BETWEEN '' AND ''

Parameters

string $column
array $range

Return Value

QueryBuilder

QueryBuilder whereBetween(string $column, array $range, string $boolean = 'and')

Where clause with comparison <>

WHERE column BETWEEN '' AND ''

Parameters

string $column
array $range
string $boolean

Return Value

QueryBuilder

Exceptions

QueryBuilderException

QueryBuilder whereNotIn(string $column, array $range)

Where clause with <> comparison

Parameters

string $column
array $range

Return Value

QueryBuilder

Exceptions

QueryBuilderException

QueryBuilder whereIn(string $column, array $range, string $boolean = 'and')

Where clause with <> comparison

Parameters

string $column
array $range
string $boolean

Return Value

QueryBuilder

Exceptions

QueryBuilderException

QueryBuilder join(string $table, string $first, mixed $comparator = '=', string|null $second = null)

Join clause

Parameters

string $table
string $first
mixed $comparator
string|null $second

Return Value

QueryBuilder

string getPrefix()

Returns the prefix.

Return Value

string

QueryBuilder setPrefix(string $prefix)

Modify the prefix

Parameters

string $prefix

Return Value

QueryBuilder

QueryBuilder leftJoin(string $table, string $first, mixed $comparator = '=', string|null $second = null)

Left Join clause

Parameters

string $table
string $first
mixed $comparator
string|null $second

Return Value

QueryBuilder

Exceptions

QueryBuilderException

QueryBuilder rightJoin(string $table, string $first, mixed $comparator = '=', string|null $second = null)

Right Join clause

Parameters

string $table
string $first
mixed $comparator
string|null $second

Return Value

QueryBuilder

Exceptions

QueryBuilderException

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"

Parameters

string $first
mixed $comparator
string $second

Return Value

QueryBuilder

Exceptions

QueryBuilderException

QueryBuilder orOn(string $first, mixed $comparator = '=', string $second = null)

Clause On, followed by a combination by a comparator <> The user has to do an "on()" before using the "orOn"

Parameters

string $first
mixed $comparator
string $second

Return Value

QueryBuilder

Exceptions

QueryBuilderException

QueryBuilder group(string $column) deprecated

deprecated

Clause Group By

Parameters

string $column

Return Value

QueryBuilder

QueryBuilder groupBy(string $column)

Clause Group By

Parameters

string $column

Return Value

QueryBuilder

QueryBuilder having(string $column, mixed $comparator = '=', mixed $value = null, string $boolean = 'and')

clause having, is used with a groupBy

Parameters

string $column
mixed $comparator
mixed $value
string $boolean

Return Value

QueryBuilder

QueryBuilder orderBy(string $column, string $type = 'asc')

Clause Order By

Parameters

string $column
string $type

Return Value

QueryBuilder

int|float max(string $column)

Max

Parameters

string $column

Return Value

int|float

int|float min(string $column)

Min

Parameters

string $column

Return Value

int|float

int|float avg(string $column)

Avg

Parameters

string $column

Return Value

int|float

int|float sum(string $column)

Sum

Parameters

string $column

Return Value

int|float

object|null last()

Get the last record

Return Value

object|null

int count(string $column = '*')

Count

Parameters

string $column

Return Value

int

object|null first()

Get the first record

Return Value

object|null

QueryBuilder take(int $limit)

Take = Limit

Parameters

int $limit

Return Value

QueryBuilder

array|object|null get(array $columns = [])

Get make, only on the select request If the first selection mode is not active

Parameters

array $columns

Return Value

array|object|null

Exceptions

QueryBuilder select(array $select = ['*'])

Add select column.

SELECT $column | SELECT column1, column2, ...

Parameters

array $select

Return Value

QueryBuilder

QueryBuilder jump(int $offset = 0)

Jump = Offset

Parameters

int $offset

Return Value

QueryBuilder

int update(array $data = [])

Update action

Parameters

array $data

Return Value

int

int remove(string $column, mixed $comparator = '=', string $value = null)

Remove simplified stream from delete.

Parameters

string $column
mixed $comparator
string $value

Return Value

int

Exceptions

QueryBuilderException

int delete()

Delete row on table

Return Value

int

int increment(string $column, int $step = 1)

Increment column

Parameters

string $column
int $step

Return Value

int

int decrement(string $column, int $step = 1)

Decrement column

Parameters

string $column
int $step

Return Value

int

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.

Parameters

string $column

The column to apply the DISTINCT clause on.

Return Value

QueryBuilder

Returns the current QueryBuilder instance.

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.

Return Value

bool

string|int|bool insertAndGetLastId(array $values)

InsertAndGetLastId action launches the insert and lastInsertId actions

Parameters

array $values

Return Value

string|int|bool

int insert(array $values)

Insert

The data to be inserted into the database.

Parameters

array $values

Return Value

int

bool drop()

Drop, remove the table

Return Value

bool

Pagination paginate(int $number_of_page, int $current = 0, int|null $chunk = null)

Paginate, make pagination system

Parameters

int $number_of_page
int $current
int|null $chunk

Return Value

Pagination

bool exists(string|null $column = null, mixed $value = null)

Check if a value already exists in the DB

Parameters

string|null $column
mixed $value

Return Value

bool

Exceptions

QueryBuilderException

string getLastInsertId(string|null $name = null)

Turn back the id of the last insertion

Parameters

string|null $name [optional]

Return Value

string

mixed jsonSerialize()

JsonSerialize implementation

void setWhereDataBinding(array $data_binding)

Define the data to associate

Parameters

array $data_binding

Return Value

void

string __toString()

__toString

Return Value

string

string toJson(int $option = 0)

Transformation automatically the result to JSON

Parameters

int $option

Return Value

string