Query
in package
implements
QueryInterface, Stringable
Query builder
Table of Contents
Interfaces
- QueryInterface
- Interface QueryInterface
- Stringable
Properties
- $db : ConnectionInterface
- Pointer to database connection.
- $bindMarker : string
- Bind marker
- $binds : array<string|int, mixed>
- The binds and their values used for binding.
- $endTime : float
- The end time in seconds with microseconds for when this query was executed.
- $errorCode : int
- The error code, if any.
- $errorString : string
- The error message, if any.
- $finalQueryString : string|null
- The final query string after binding, etc.
- $originalQueryString : string
- The query string, as provided by the user.
- $startTime : float|string
- The start time in seconds with microseconds for when this query was executed.
- $swappedQueryString : string|null
- The query string if table prefix has been swapped.
Methods
- __construct() : mixed
- __toString() : string
- Return text representation of the query
- debugToolbarDisplay() : string
- Returns string to display in debug toolbar
- getDuration() : string
- Returns the duration of this query during execution, or null if the query has not been executed yet.
- getErrorCode() : int
- Returns the error code created while executing this statement.
- getErrorMessage() : string
- Returns the error message created while executing this statement.
- getOriginalQuery() : string
- Returns the original SQL that was passed into the system.
- getQuery() : mixed
- Returns the final, processed query string after binding, etal has been performed.
- getStartTime() : float|string
- Returns the start time in seconds with microseconds.
- hasError() : bool
- Reports whether this statement created an error not.
- isWriteType() : bool
- Determines if the statement is a write-type query or not.
- setBinds() : $this
- Will store the variables to bind into the query later.
- setDuration() : $this
- Records the execution time of the statement using microtime(true) for it's start and end values. If no end value is present, will use the current time to determine total duration.
- setError() : $this
- Stores the error description that happened for this query.
- setQuery() : $this
- Sets the raw query string to use for this statement.
- swapPrefix() : $this
- Swaps out one table prefix for a new one.
- compileBinds() : mixed
- Escapes and inserts any binds into the finalQueryString property.
- matchNamedBinds() : string
- Match bindings
- matchSimpleBinds() : string
- Match bindings
Properties
$db
Pointer to database connection.
public
ConnectionInterface
$db
Mainly for escaping features.
$bindMarker
Bind marker
protected
string
$bindMarker
= '?'
Character used to identify values in a prepared statement.
$binds
The binds and their values used for binding.
protected
array<string|int, mixed>
$binds
= []
$endTime
The end time in seconds with microseconds for when this query was executed.
protected
float
$endTime
$errorCode
The error code, if any.
protected
int
$errorCode
$errorString
The error message, if any.
protected
string
$errorString
$finalQueryString
The final query string after binding, etc.
protected
string|null
$finalQueryString
$originalQueryString
The query string, as provided by the user.
protected
string
$originalQueryString
$startTime
The start time in seconds with microseconds for when this query was executed.
protected
float|string
$startTime
$swappedQueryString
The query string if table prefix has been swapped.
protected
string|null
$swappedQueryString
Methods
__construct()
public
__construct(ConnectionInterface $db) : mixed
Parameters
- $db : ConnectionInterface
__toString()
Return text representation of the query
public
__toString() : string
Return values
stringdebugToolbarDisplay()
Returns string to display in debug toolbar
public
debugToolbarDisplay() : string
Return values
stringgetDuration()
Returns the duration of this query during execution, or null if the query has not been executed yet.
public
getDuration([int $decimals = 6 ]) : string
Parameters
- $decimals : int = 6
-
The accuracy of the returned time.
Return values
stringgetErrorCode()
Returns the error code created while executing this statement.
public
getErrorCode() : int
Return values
intgetErrorMessage()
Returns the error message created while executing this statement.
public
getErrorMessage() : string
Return values
stringgetOriginalQuery()
Returns the original SQL that was passed into the system.
public
getOriginalQuery() : string
Return values
stringgetQuery()
Returns the final, processed query string after binding, etal has been performed.
public
getQuery() : mixed
getStartTime()
Returns the start time in seconds with microseconds.
public
getStartTime([bool $returnRaw = false ][, int $decimals = 6 ]) : float|string
Parameters
- $returnRaw : bool = false
- $decimals : int = 6
Return values
float|stringhasError()
Reports whether this statement created an error not.
public
hasError() : bool
Return values
boolisWriteType()
Determines if the statement is a write-type query or not.
public
isWriteType() : bool
Return values
boolsetBinds()
Will store the variables to bind into the query later.
public
setBinds(array<string|int, mixed> $binds[, bool $setEscape = true ]) : $this
Parameters
- $binds : array<string|int, mixed>
- $setEscape : bool = true
Return values
$thissetDuration()
Records the execution time of the statement using microtime(true) for it's start and end values. If no end value is present, will use the current time to determine total duration.
public
setDuration(float $start[, float|null $end = null ]) : $this
Parameters
- $start : float
- $end : float|null = null
Return values
$thissetError()
Stores the error description that happened for this query.
public
setError(int $code, string $error) : $this
Parameters
- $code : int
- $error : string
Return values
$thissetQuery()
Sets the raw query string to use for this statement.
public
setQuery(string $sql[, mixed $binds = null ][, bool $setEscape = true ]) : $this
Parameters
- $sql : string
- $binds : mixed = null
- $setEscape : bool = true
Return values
$thisswapPrefix()
Swaps out one table prefix for a new one.
public
swapPrefix(string $orig, string $swap) : $this
Parameters
- $orig : string
- $swap : string
Return values
$thiscompileBinds()
Escapes and inserts any binds into the finalQueryString property.
protected
compileBinds() : mixed
Tags
matchNamedBinds()
Match bindings
protected
matchNamedBinds(string $sql, array<string|int, mixed> $binds) : string
Parameters
- $sql : string
- $binds : array<string|int, mixed>
Return values
stringmatchSimpleBinds()
Match bindings
protected
matchSimpleBinds(string $sql, array<string|int, mixed> $binds, int $bindCount, int $ml) : string
Parameters
- $sql : string
- $binds : array<string|int, mixed>
- $bindCount : int
- $ml : int