Class yii\db\Expression

Inheritanceyii\db\Expression » yii\base\BaseObject
Implementsyii\base\Configurable, yii\db\ExpressionInterface
Available since version2.0
Source Code https://github.com/yiisoft/yii2/blob/master/framework/db/Expression.php

Expression represents a DB expression that does not 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 = (new \yii\db\Query)->select($expression)->scalar();  // SELECT NOW();
echo $now; // prints the current date

Expression objects are mainly created for passing raw SQL expressions to methods of yii\db\Query, yii\db\ActiveQuery, and related classes.

An expression can also be bound with parameters specified via $params.

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$expression string The DB expression yii\db\Expression
$params array List of parameters that should be bound for this expression. yii\db\Expression

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. yii\db\Expression
__get() Returns the value of an object property. yii\base\BaseObject
__isset() Checks if a property is set, i.e. defined and not null. yii\base\BaseObject
__set() Sets value of an object property. yii\base\BaseObject
__toString() String magic method. yii\db\Expression
__unset() Sets an object property to null. yii\base\BaseObject
canGetProperty() Returns a value indicating whether a property can be read. yii\base\BaseObject
canSetProperty() Returns a value indicating whether a property can be set. yii\base\BaseObject
className() Returns the fully qualified name of this class. yii\base\BaseObject
hasMethod() Returns a value indicating whether a method is defined. yii\base\BaseObject
hasProperty() Returns a value indicating whether a property is defined. yii\base\BaseObject
init() Initializes the object. yii\base\BaseObject

Property Details

$expression public property

The DB expression

public string $expression null
$params public property

List of parameters that should be bound for this expression. The keys are placeholders appearing in $expression and the values are the corresponding parameter values.

public array $params = []

Method Details

__construct() public method

Constructor.

public void __construct ( $expression, $params = [], $config = [] )
$expression string

The DB expression

$params array

Parameters

$config array

Name-value pairs that will be used to initialize the object properties

__toString() public method

String magic method.

public string __toString ( )
return string

The DB expression.