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 $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 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 __construct( string $expression, array $params = [] ): mixed
$expression string

The DB expression.

$params array

List of parameters to bind to this expression. The keys are placeholders appearing in $expression and the values are the corresponding parameter values.

                public function __construct(
    public readonly string $expression,
    public readonly array $params = [],
) {}

            
__toString() public method

public __toString( ): string
return string

The expression.

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