Final Class Yiisoft\Db\Expression\Expression
| Inheritance | Yiisoft\Db\Expression\Expression |
|---|---|
| Implements | Stringable, Yiisoft\Db\Expression\ExpressionInterface |
Represents a DB expression that doesn't need escaping or quoting.
When an Expression object is embedded within a SQL statement or fragment, it will be replaced with the {@see \Yiisoft\Db\Expression\expression} property value without any DB escaping or quoting.
For example,
$expression = new Expression('NOW()');
$now = $db->select($expression)->scalar(); // SELECT NOW();
echo $now; // prints the current date
Expression objects are mainly created for passing raw SQL expressions to methods of {@see \Yiisoft\Db\Query\QueryInterface} and related classes.
Public Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $expression | string | Yiisoft\Db\Expression\Expression | |
| $params | array | Yiisoft\Db\Expression\Expression |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Db\Expression\Expression | |
| __toString() | Yiisoft\Db\Expression\Expression |
Property Details
Method Details
| public mixed __construct ( string $expression, array $params = [] ) | ||
| $expression | string |
The DB expression. |
| $params | array |
List of parameters to bind to this expression. The keys are placeholders appearing in {@see \Yiisoft\Db\Expression\expression} and the values are the corresponding parameter values. |
public function __construct(
public readonly string $expression,
public readonly array $params = [],
) {}
| public string __toString ( ) | ||
| return | string |
The expression. |
|---|---|---|
public function __toString(): string
{
return $this->expression;
}
Signup or Login in order to comment.