Documentation

Menu

## QueryBuilder
in package

QueryBuilder.php : 23

### Table of Contents

#### Properties

$connection : DriverBase
$debugger : Debugger
$debugGlobalMode : bool|string
$debugOnceMode : bool|string
  Debug mode for the query builder.
$fields : string
$from : string
$lastInsertId : bool|string
$parameters : Parameters
$placeholders : array<int|string, mixed>
$queryString : string
$queryType : string
$rawQuery : string
$result : Result
$table : string
$values : array<string, mixed>
$where : Where

#### Methods

__construct() : mixed
  Constructor for the QueryBuilder class.
debugOnce() : self
  Sets the debug mode for the query builder.
delete() : self
  Deletes records from the specified table based on the given conditions.
distinct() : self
  Sets the DISTINCT keyword in the query.
execute() : bool|int
  Executes a raw query and returns the result.
executeQuery() : bool
  Execute the SELECT query.
executeStatement() : bool|int
  Executes the prepared statement and returns the result.
fetch() : mixed
  Fetches the next row from the result set as an object or an array.
fetchAll() : mixed
  Fetches all rows from the database using the specified fetch mode.
from() : $this
  Set the table with optional JOIN clauses to select from.
getDebug() : View
  Get the debug view for the query builder.
getDebugMode() : bool|string
  Get the debug mode value.
getFields() : string
  Get the fields to be selected in the query.
getFrom() : string
  Get the table name from the query builder.
getHTML() : string
  This function returns records from a SQL query as an HTML table.
getLastInsertId() : bool|string
  Get the last insert ID.
getMaximumValue() : mixed
  Get the maximum value from a specific table field.
getParameters() : Parameters
  Get the parameters used in the query.
getQueryType() : string
  Get the query type.
getRawQuery() : string
  Get the raw SQL query string.
getResult() : Result
  Get the result of the query.
getTable() : string
  Get the table name associated with the query builder.
getValues() : array<string, mixed>
  Get the values of the query.
getWhere() : Where
  Get the Where object associated with this QueryBuilder.
groupBy() : self
  Set the GROUP BY clause for the query.
insert() : self
  Insert a new row into the specified table with the given values.
limit() : self
  Set the LIMIT clause for the query.
numRows() : int|false
  Returns the number of rows in the result set of the current query.
orderBy() : self
  Set the ORDER BY clause for the query.
parameters() : self
  Set the parameters for the query.
placeholders() : self
  Set the placeholders for the query.
query() : self
select() : self
  Set the columns to select from the table.
setDebug() : void
  Sets the debug mode for the query builder.
transactionBegin() : bool
  Begin transaction processing
transactionCommit() : bool
  Commit and end transaction processing.
transactionRollback() : bool
  Roll back transaction processing.
update() : self
  Update records in the specified table.
where() : self
  Set the WHERE clause for the query.
bindValues() : PDOStatement
  Binds placeholders values to a prepared statement.
clear() : void
  Clears the query builder by resetting all the properties.
dumpDebug() : void
  Dumps the debug information for the query builder.
getSqlForDelete() : string
getSqlForInsert() : string
  Returns the SQL query string for an INSERT statement.
getSqlForSelect() : string
  Returns the SQL query for the SELECT statement.
getSqlForUpdate() : string
  Returns the SQL query string for an UPDATE statement.
getSqlStatement() : string
  Get the SQL statement.

### Properties

#### $connection

QueryBuilder.php : 27
`private DriverBase $connection`

#### $debugger

QueryBuilder.php : 59
`private Debugger $debugger`

#### $debugGlobalMode

QueryBuilder.php : 76
`private bool|string $debugGlobalMode = false`

#### $debugOnceMode

QueryBuilder.php : 74

Debug mode for the query builder.

`private bool|string $debugOnceMode = false`

debugGlobalMode is the global debug mode for the class. debugOnceMode is the debug mode for a single query.

If debugOnceMode is false, the global debug mode will be used. If debugOnceMode is set, it will override the global debug mode. Both can be set to false, true, or 'silent'.

If set to true, the class will display detailed error messages. If set to 'silent', the class will register all error messages, which can be retrieved using the getDebug() method.

#### $fields

QueryBuilder.php : 31
`private string $fields`

#### $from

QueryBuilder.php : 29
`private string $from`

#### $lastInsertId

QueryBuilder.php : 50
`private bool|string $lastInsertId`

#### $parameters

QueryBuilder.php : 46
`private Parameters $parameters`

#### $placeholders

QueryBuilder.php : 36
`private array<int|string, mixed> $placeholders = []`

An indexed or associative array to store the placeholders used in the query.

#### $queryString

QueryBuilder.php : 38
`private string $queryString`

#### $queryType

QueryBuilder.php : 40
`private string $queryType`

#### $rawQuery

QueryBuilder.php : 42
`private string $rawQuery`

#### $result

QueryBuilder.php : 48
`private Result $result`

#### $table

QueryBuilder.php : 52
`private string $table`

#### $values

QueryBuilder.php : 57
`private array<string, mixed> $values`

Associative array containing the fields and values

#### $where

QueryBuilder.php : 44
`private Where $where`

### Methods

#### __construct()

QueryBuilder.php : 83

Constructor for the QueryBuilder class.

`public __construct(DriverBase $driverBase, Where $where, Parameters $parameters, Result $result) : mixed`

##### Parameters

$driverBase : DriverBase

  The database connection object.

$where : Where
$parameters : Parameters
$result : Result

#### debugOnce()

QueryBuilder.php : 890

Sets the debug mode for the query builder.

`public debugOnce(bool|string $mode) : self`

##### Parameters

$mode : bool|string

  The debug mode to set.

##### Return values

self —

The current instance of the QueryBuilder.

#### delete()

QueryBuilder.php : 273

Deletes records from the specified table based on the given conditions.

`public delete(string $table, array<int|string, mixed>|string $where) : self`

##### Parameters

$table : string

  The name of the table to delete records from.

$where : array<int|string, mixed>|string

  The condition(s) to be used in the delete query.

##### Return values

self —

The current instance of the QueryBuilder.

#### distinct()

QueryBuilder.php : 149

Sets the DISTINCT keyword in the query.

`public distinct() : self`

##### Return values

self

#### execute()

QueryBuilder.php : 290

Executes a raw query and returns the result.

`public execute() : bool|int`

##### Return values

bool|int —

The result of the query execution.

#### executeQuery()

QueryBuilder.php : 313

Execute the SELECT query.

`public executeQuery() : bool`

##### Return values

bool —

True if the query was successful, false otherwise.

#### executeStatement()

QueryBuilder.php : 375

Executes the prepared statement and returns the result.

`public executeStatement() : bool|int`

##### Return values

bool|int —

The number of affected rows or false if there was an error.

#### fetch()

QueryBuilder.php : 559

Fetches the next row from the result set as an object or an array.

`public fetch([int $fetch_parameters = PDO::FETCH_OBJ ]) : mixed`

##### Parameters

$fetch_parameters : int = PDO::FETCH_OBJ

  The fetch style to use. Default is \PDO::FETCH_OBJ.

##### Return values

mixed —

The fetched row as an object or an array, depending on the fetch style.

#### fetchAll()

QueryBuilder.php : 570

Fetches all rows from the database using the specified fetch mode.

`public fetchAll([int $fetch_parameters = PDO::FETCH_OBJ ]) : mixed`

##### Parameters

$fetch_parameters : int = PDO::FETCH_OBJ

  The fetch mode to use. Defaults to \PDO::FETCH_OBJ.

##### Return values

mixed —

An array of rows fetched from the database.

#### from()

QueryBuilder.php : 126

Set the table with optional JOIN clauses to select from.

`public from(string $from) : $this`

##### Parameters

$from : string

  The SQL FROM statement with optional joins. Example: 'table1 INNER JOIN table2 ON table1.id = table2.id'.

##### Return values

$this —

The current instance of the QueryBuilder.

#### getDebug()

QueryBuilder.php : 906

Get the debug view for the query builder.

`public getDebug() : View`

##### Return values

View —

The debug view.

#### getDebugMode()

QueryBuilder.php : 931

Get the debug mode value.

`public getDebugMode() : bool|string`

##### Return values

bool|string —

The debug mode value.

#### getFields()

QueryBuilder.php : 690

Get the fields to be selected in the query.

`public getFields() : string`

(for PHPUnit testing purposes only).

##### Return values

string —

The fields to be selected.

#### getFrom()

QueryBuilder.php : 701

Get the table name from the query builder.

`public getFrom() : string`

(for PHPUnit testing purposes only).

##### Return values

string —

The From query.

#### getHTML()

QueryBuilder.php : 585

This function returns records from a SQL query as an HTML table.

`public getHTML(array<string|int, mixed> $records[, bool $showCount = true ][, string|null $tableAttr = null ][, string|null $thAttr = null ][, string|null $tdAttr = null ]) : string`

##### Parameters

$records : array<string|int, mixed>

  The records set - can be an array or array of objects according to the fetch parameters.

$showCount : bool = true

  (Optional) true if you want to show the row count, false if you do not want to show the count.

$tableAttr : string|null = null

  (Optional) Comma separated attributes for the table. e.g: 'class=my-class, style=color:#222'.

$thAttr : string|null = null

  (Optional) Comma separated attributes for the header row. e.g: 'class=my-class, style=font-weight:bold'.

$tdAttr : string|null = null

  (Optional) Comma separated attributes for the cells. e.g: 'class=my-class, style=font-weight:normal'.

##### Return values

string —

HTML containing a table with all records listed.

#### getLastInsertId()

QueryBuilder.php : 650

Get the last insert ID.

`public getLastInsertId() : bool|string`

##### Return values

bool|string —

The last insert ID or false if there was an error.

#### getMaximumValue()

QueryBuilder.php : 667

Get the maximum value from a specific table field.

`public getMaximumValue(string $table, string $field) : mixed`

##### Parameters

$table : string
$field : string

##### Return values

mixed —

the field value or false if no value is found.

#### getParameters()

QueryBuilder.php : 712

Get the parameters used in the query.

`public getParameters() : Parameters`

(for PHPUnit testing purposes only).

##### Return values

Parameters —

The parameters used in the query.

#### getQueryType()

QueryBuilder.php : 723

Get the query type.

`public getQueryType() : string`

(for PHPUnit testing purposes only).

##### Return values

string —

The query type.

#### getRawQuery()

QueryBuilder.php : 734

Get the raw SQL query string.

`public getRawQuery() : string`

(for PHPUnit testing purposes only).

##### Return values

string —

The raw SQL query string.

#### getResult()

QueryBuilder.php : 745

Get the result of the query.

`public getResult() : Result`

(for PHPUnit testing purposes only).

##### Return values

Result —

The result of the query.

#### getTable()

QueryBuilder.php : 756

Get the table name associated with the query builder.

`public getTable() : string`

(for PHPUnit testing purposes only).

##### Return values

string —

The table name.

#### getValues()

QueryBuilder.php : 767

Get the values of the query.

`public getValues() : array<string, mixed>`

(for PHPUnit testing purposes only).

##### Return values

array<string, mixed> —

The values of the query.

#### getWhere()

QueryBuilder.php : 778

Get the Where object associated with this QueryBuilder.

`public getWhere() : Where`

(for PHPUnit testing purposes only).

##### Return values

Where —

The Where object.

#### groupBy()

QueryBuilder.php : 161

Set the GROUP BY clause for the query.

`public groupBy(string $groupBy) : self`

##### Parameters

$groupBy : string

  The GROUP BY clause.

##### Return values

self —

The current instance of the QueryBuilder.

#### insert()

QueryBuilder.php : 232

Insert a new row into the specified table with the given values.

`public insert(string $table, array<string, mixed> $values) : self`

##### Parameters

$table : string

  The name of the table to insert into.

$values : array<string, mixed>

  An associative array of column-value pairs to insert.

##### Return values

self —

The QueryBuilder instance for method chaining.

#### limit()

QueryBuilder.php : 173

Set the LIMIT clause for the query.

`public limit(int|string $limit) : self`

##### Parameters

$limit : int|string

  The LIMIT clause.

##### Return values

self —

The current instance of the QueryBuilder.

#### numRows()

QueryBuilder.php : 788

Returns the number of rows in the result set of the current query.

`public numRows() : int|false`

##### Return values

int|false —

The number of rows, or false on failure.

#### orderBy()

QueryBuilder.php : 185

Set the ORDER BY clause for the query.

`public orderBy(string $orderBy) : self`

##### Parameters

$orderBy : string

  The ORDER BY clause.

##### Return values

self —

The current instance of the QueryBuilder.

#### parameters()

QueryBuilder.php : 197

Set the parameters for the query.

`public parameters(array<string, bool|int|string> $parameters) : self`

##### Parameters

$parameters : array<string, bool|int|string>

  An associative array of parameter names and values.

##### Return values

self —

The QueryBuilder instance.

#### placeholders()

QueryBuilder.php : 212

Set the placeholders for the query.

`public placeholders(array<int|string, mixed> $placeholders) : self`

##### Parameters

$placeholders : array<int|string, mixed>

  An indexed or associative array to store the placeholders used in the query.

##### Return values

self —

The QueryBuilder instance.

#### query()

QueryBuilder.php : 91
`public query(string $sql) : self`

##### Parameters

$sql : string

##### Return values

self

#### select()

QueryBuilder.php : 106

Set the columns to select from the table.

`public select(string|array<string|int, string> $fields) : self`

##### Parameters

$fields : string|array<string|int, string>

  The columns to select. Can be a string or an array of strings. If it's an array, the columns will be joined with a comma.

##### Return values

self —

The current instance of the QueryBuilder.

#### setDebug()

QueryBuilder.php : 916

Sets the debug mode for the query builder.

`public setDebug(bool|string $mode) : void`

##### Parameters

$mode : bool|string

  The debug mode to set.

#### transactionBegin()

QueryBuilder.php : 484

Begin transaction processing

`public transactionBegin() : bool`

##### Tags

throws
  Exception

  If there is an error.

##### Return values

bool —

Returns true if the transaction begins successfully, false otherwise.

#### transactionCommit()

QueryBuilder.php : 510

Commit and end transaction processing.

`public transactionCommit() : bool`

##### Tags

throws
  Exception

  If there is an error.

##### Return values

bool —

Returns true if the transaction is committed successfully, false otherwise.

#### transactionRollback()

QueryBuilder.php : 535

Roll back transaction processing.

`public transactionRollback() : bool`

##### Tags

throws
  Exception

  If there is an error.

##### Return values

bool —

Returns true if the transaction is rolled back successfully, false otherwise.

#### update()

QueryBuilder.php : 253

Update records in the specified table.

`public update(string $table, array<string, mixed> $values, array<int|string, mixed>|string $where) : self`

##### Parameters

$table : string

  The name of the table to update.

$values : array<string, mixed>

  An associative array of column-value pairs to update.

$where : array<int|string, mixed>|string

  The condition to filter the records to be updated. Can be a string or an array of conditions. If it's an array, the conditions will be joined with AND.

##### Return values

self —

The current instance of the QueryBuilder.

#### where()

QueryBuilder.php : 139

Set the WHERE clause for the query.

`public where(array<int|string, mixed>|string $where) : self`

##### Parameters

$where : array<int|string, mixed>|string

  The WHERE clause. Can be a string or an array of conditions. If it's an array, the conditions will be joined with AND.

##### Return values

self —

The current instance of the QueryBuilder.

#### bindValues()

QueryBuilder.php : 942

Binds placeholders values to a prepared statement.

`private bindValues(PDOStatement $query) : PDOStatement`

##### Parameters

$query : PDOStatement

  The prepared statement to bind values to.

##### Return values

PDOStatement —

The prepared statement with bound values.

#### clear()

QueryBuilder.php : 968

Clears the query builder by resetting all the properties.

`private clear() : void`

##### Tags

access

  private

#### dumpDebug()

QueryBuilder.php : 988

Dumps the debug information for the query builder.

`private dumpDebug(PDOStatement|null $pdoStatement, int|float|null $time[, string|null $errorMessage = null ]) : void`

##### Parameters

$pdoStatement : PDOStatement|null

  The PDOStatement object representing the query.

$time : int|float|null

  The execution time of the query.

$errorMessage : string|null = null

  The error message, if any.

#### getSqlForDelete()

QueryBuilder.php : 1135
`private getSqlForDelete() : string`

##### Return values

string

#### getSqlForInsert()

QueryBuilder.php : 1105

Returns the SQL query string for an INSERT statement.

`private getSqlForInsert() : string`

##### Return values

string —

The SQL query string.

#### getSqlForSelect()

QueryBuilder.php : 1016

Returns the SQL query for the SELECT statement.

`private getSqlForSelect() : string`

##### Return values

string —

The SQL query for the SELECT statement.

#### getSqlForUpdate()

QueryBuilder.php : 1118

Returns the SQL query string for an UPDATE statement.

`private getSqlForUpdate() : string`

##### Return values

string —

The SQL query string.

#### getSqlStatement()

QueryBuilder.php : 1083

Get the SQL statement.

`private getSqlStatement() : string`

##### Return values

string —

The SQL statement.

## Search results