Connection
in package
Uses
Interaction
Table of Contents
- $booter : z_framework
- $cakePHPDatabase : Connection
- $connectTimeout : int
- $insertId : int|string|null
- $lastConnect : int
- $lastHeartbeat : int
- $result : null|bool|mysqli_result
- $conn : mysqli
- $password : string
- $stmt : mysqli_stmt
- $user : string
- __construct() : mixed
- __destruct() : mixed
- Closes the database connection on exit
- assertConnection() : mixed
- 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
- disconnect() : void
- Disconnect from the database
- exec() : Connection
- Executes a query as prepared statement
- execQuery() : Connection
- Executes a CakePHP Query object using ZubZet`s own value binder to extract the SQL and bindings, then executing it as a prepared statement
- executeMultiQuery() : bool
- getDatabaseConnection() : mysqli
- 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
- getInsertId() : int|string|null
- Returns the id of the last inserted element
- getTableWhere() : array<string|int, array<string|int, mixed>>
- Selects a full table of specified fields of it filtered with an additional where statement. It returns the result as two dimensional array
- heartbeat() : bool
- Run a very lightweight query to keep the connection alive
- 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>
- Returns one line of the last query
- switchUser() : void
- connect() : mixed
Properties
$booter
public
z_framework
$booter
$cakePHPDatabase
public
Connection
$cakePHPDatabase
$connectTimeout
public
int
$connectTimeout
$insertId
public
int|string|null
$insertId
Last insert id
$lastConnect
public
int
$lastConnect
$lastHeartbeat
public
int
$lastHeartbeat
$result
public
null|bool|mysqli_result
$result
Result of the last query
$conn
private
mysqli
$conn
$password
private
string
$password
$stmt
private
mysqli_stmt
$stmt
$user
private
string
$user
Methods
__construct()
public
__construct(z_framework &$booter) : mixed
Parameters
- $booter : z_framework
Return values
mixed —__destruct()
Closes the database connection on exit
public
__destruct() : mixed
Return values
mixed —assertConnection()
public
assertConnection() : mixed
Return values
mixed —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 $ignoreField = null ][, string $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
-
field of a dataset to ignore
- $ignoreValue : string = null
-
value of the in the argument before defined field of the dataset to ignore
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
disconnect()
Disconnect from the database
public
disconnect() : void
Return values
void —exec()
Executes a query as prepared statement
public
exec(string $query) : Connection
Parameters
- $query : string
-
Query written as prepared statement (that thing with the question marks as placeholders)
Return values
Connection —Returning this for chaining
execQuery()
Executes a CakePHP Query object using ZubZet`s own value binder to extract the SQL and bindings, then executing it as a prepared statement
public
execQuery(Query $query) : Connection
Parameters
- $query : Query
-
The CakePHP Query object to execute
Return values
Connection —Returning this for chaining
executeMultiQuery()
public
executeMultiQuery(string $query[, bool $throwOnFailure = true ]) : bool
Parameters
- $query : string
- $throwOnFailure : bool = true
Return values
bool —getDatabaseConnection()
public
getDatabaseConnection() : mysqli
Return values
mysqli —getFullTable()
Selects a full table or specified fields of it and returns the result as two dimensional array
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
getTableWhere()
Selects a full table of specified fields of it filtered with an additional where statement. It returns the result as two dimensional array
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...);
- $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
heartbeat()
Run a very lightweight query to keep the connection alive
public
heartbeat([mixed $waitForTimeout = true ][, mixed $timeoutBuffer = 30 ]) : bool
Parameters
- $waitForTimeout : mixed = true
- $timeoutBuffer : mixed = 30
Return values
bool —Was the heartbeat successful
mergeAsGroup()
Converts the result of the last query into a grouped array
public
mergeAsGroup(string $groupBy[, string $subElement = null ]) : array<string|int, array<string|int, mixed>>
Parameters
- $groupBy : string
-
The field, by which the array is grouped by
- $subElement : string = null
-
If set, the only a sub element of the grouped element is returned
Return values
array<string|int, array<string|int, mixed>> —Results of the last query as two dimensional array with the index as thr groupBy value
resultToArray()
Converts the result of the last query into an array and returns it
public
resultToArray([mixed $out = [] ]) : array<string|int, array<string|int, mixed>>
Parameters
- $out : mixed = []
Return values
array<string|int, array<string|int, mixed>> —Results of the last query as two dimensional array
resultToLine()
Returns one line of the last query
public
resultToLine() : array<string|int, mixed>
Return values
array<string|int, mixed> —Line of the last result
switchUser()
public
switchUser(string $user, string $password) : void
Parameters
- $user : string
- $password : string
Return values
void —connect()
private
connect() : mixed