Interaction
Table of Contents
- $callingModel : Model|null
- $insertId : int|string|null
- $result : null|bool|mysqli_result
- checkIfExists() : bool
- Checks if a value exists in a table.
- checkIfUnique() : bool
- Checks if a value is already in a table. Can also ignore a dataset.
- countResults() : int
- Returns the number of results in the last query
- countTableEntries() : int
- Returns the number of datasets in a table
- getFullTable() : array<string|int, array<string|int, mixed>>
- Selects a full table or specified fields of it and returns the result as two dimensional array Table and fields are not escaped, so never put user input in them.
- getInsertId() : int|string|null
- Returns the id of the last inserted element
- getTableWhere() : array<string|int, array<string|int, mixed>>
- Selects a table or specified fields of it, filtered with a where statement, and returns the result as two dimensional array. Only $values are bound, $table, $fields and $where are not escaped
- mergeAsGroup() : array<string|int, array<string|int, mixed>>
- Converts the result of the last query into a grouped array
- resultToArray() : array<string|int, array<string|int, mixed>>
- Converts the result of the last query into an array and returns it
- resultToLine() : array<string|int, mixed>|null
- Returns the next line of the last query
Properties
$callingModel
public
Model|null
$callingModel
= null
A reference to the model that is currently handling the query, if any
$insertId
public
int|string|null
$insertId
Last insert id
$result
public
null|bool|mysqli_result
$result
Result of the last query
Methods
checkIfExists()
Checks if a value exists in a table.
public
checkIfExists(string $table, string $field, mixed $value) : bool
Table and field names are inserted unescaped. Check your input.
Parameters
- $table : string
-
Name of the table to check in
- $field : string
-
Name of the field in that a value should exist
- $value : mixed
-
Value to check for
Return values
bool —True when exists
checkIfUnique()
Checks if a value is already in a table. Can also ignore a dataset.
public
checkIfUnique(string $table, string $field, mixed $value[, string|null $ignoreField = null ][, mixed|null $ignoreValue = null ]) : bool
Table and field names are inserted unescaped. Check your input.
Parameters
- $table : string
-
Name of the table to check in
- $field : string
-
Field to check in
- $value : mixed
-
Value to check for
- $ignoreField : string|null = null
-
Field used to exclude rows; rows where it equals $ignoreValue are not counted, null disables the exclusion (inserted unescaped)
- $ignoreValue : mixed|null = null
-
Value of $ignoreField that marks the rows to exclude, e.g. the id of the row being edited
Return values
bool —True when not exists
countResults()
Returns the number of results in the last query
public
countResults() : int
Return values
int —Number of results in the last query
countTableEntries()
Returns the number of datasets in a table
public
countTableEntries(string $table) : int
Parameters
- $table : string
-
Name of the table in the database
Return values
int —Number of datasets in the specified table
getFullTable()
Selects a full table or specified fields of it and returns the result as two dimensional array Table and fields are not escaped, so never put user input in them.
public
getFullTable(string $table[, string $fields = "*" ]) : array<string|int, array<string|int, mixed>>
Parameters
- $table : string
-
Name of the table in the database
- $fields : string = "*"
-
Fields to select. Formatted as in an SQL query ("*", "a, b, c"...)
Return values
array<string|int, array<string|int, mixed>> —A two dimensional array with the results of the select statement
getInsertId()
Returns the id of the last inserted element
public
getInsertId() : int|string|null
Return values
int|string|null —Id of the last inserted element; 0 if the last query generated no AUTO_INCREMENT id, null before the first query
getTableWhere()
Selects a table or specified fields of it, filtered with a where statement, and returns the result as two dimensional array. Only $values are bound, $table, $fields and $where are not escaped
public
getTableWhere(string $table[, string $fields = "*" ][, string $where = "" ][, string $types = "" ][, array<string|int, mixed> $values = [] ]) : array<string|int, array<string|int, mixed>>
Parameters
- $table : string
-
Name of the table in the database
- $fields : string = "*"
-
Fields to select. Formatted as in a SQL query ("*", "a, b, c"...)
- $where : string = ""
-
The where statement in the query. Formatted as in a SQL query (a = 4 AND c = 4...). Required in practice: the empty default produces invalid SQL ("WHERE ")
- $types : string = ""
-
String with the types. Conform to prepared statements ("ssis")
- $values : array<string|int, mixed> = []
-
The values to insert in the prepared statement
Return values
array<string|int, array<string|int, mixed>> —two dimensional array with table data
mergeAsGroup()
Converts the result of the last query into a grouped array
public
mergeAsGroup(string $groupBy[, string|null $subElement = null ]) : array<string|int, array<string|int, mixed>>
Parameters
- $groupBy : string
-
The field, by which the array is grouped by
- $subElement : string|null = null
-
If set, groups hold only this column's plain values instead of full rows
Return values
array<string|int, array<string|int, mixed>> —Results of the last query as two dimensional array with the index as the groupBy value
resultToArray()
Converts the result of the last query into an array and returns it
public
resultToArray([array<string|int, array<string|int, mixed>> $out = [] ]) : array<string|int, array<string|int, mixed>>
Parameters
- $out : array<string|int, array<string|int, mixed>> = []
-
Existing rows the result rows are appended to
Tags
Return values
array<string|int, array<string|int, mixed>> —Results of the last query as two dimensional array
resultToLine()
Returns the next line of the last query
public
resultToLine() : array<string|int, mixed>|null
Return values
array<string|int, mixed>|null —Next line of the last result, null once the result is exhausted or empty