0 follower

Final Class Yiisoft\Db\Expression\Expression

InheritanceYiisoft\Db\Expression\Expression
ImplementsStringable, 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.

Property Details

Hide inherited properties

$expression public property
public string $expression null
$params public property
public array $params = []

Method Details

Hide inherited methods

__construct() public method

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 = [],
) {}

            
__toString() public method

public string __toString ( )
return string

The expression.

                public function __toString(): string
{
    return $this->expression;
}