Query
abstract class Query implements PlaceholderInterface (View source)
Base class for query builders.
Note that query builders use PHP's magic __toString() method to compile the query object into a prepared statement.
Properties
| protected Connection | $connection | The connection object on which to run this query. |
|
| protected string | $connectionTarget | The target of the connection object. |
|
| protected string | $connectionKey | The key of the connection object. |
|
| protected array | $queryOptions | The query options to pass on to the connection object. |
|
| protected string | $uniqueIdentifier | A unique identifier for this query object. |
|
| protected int | $nextPlaceholder | The placeholder counter. |
|
| protected array | $comments | An array of comments that can be prepended to a query. |
Methods
Implements the magic __sleep function to disconnect from the database.
Implements the magic __wakeup function to reconnect to the database.
Implements the magic __clone function.
Runs the query against the database.
Implements PHP magic __toString method to convert the query to a string.
Returns a unique identifier for this object.
Gets the next placeholder value for this query object.
Adds a comment to the query.
Returns a reference to the comments array for the query.
Details
__construct(Connection $connection, array $options)
Constructs a Query object.
__sleep()
Implements the magic __sleep function to disconnect from the database.
__wakeup()
Implements the magic __wakeup function to reconnect to the database.
__clone()
Implements the magic __clone function.
abstract protected StatementInterface|null
execute()
Runs the query against the database.
abstract string
__toString()
Implements PHP magic __toString method to convert the query to a string.
The toString operation is how we compile a query object to a prepared statement.
uniqueIdentifier()
Returns a unique identifier for this object.
The
nextPlaceholder()
Gets the next placeholder value for this query object.
$this
comment($comment)
Adds a comment to the query.
By adding a comment to a query, you can more easily find it in your query log or the list of active queries on an SQL server. This allows for easier debugging and allows you to more easily find where a query with a performance problem is being generated.
The comment string will be sanitized to remove * / and other characters that may terminate the string early so as to avoid SQL injection attacks.
array
getComments()
Returns a reference to the comments array for the query.
Because this method returns by reference, alter hooks may edit the comments array directly to make their changes. If just adding comments, however, the use of comment() is preferred.
Note that this method must be called by reference as well: