Class yii\db\Expression
Inheritance | yii\db\Expression » yii\base\BaseObject |
---|---|
Implements | yii\base\Configurable, yii\db\ExpressionInterface |
Available since version | 2.0 |
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
属性Property | 类型 Type | 简介 Description | 定义在 Defined 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
方法 Method | 简介 Description | 定义在 Defined 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
The DB expression
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.
方法详情 Method Details
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 |
String magic method.
public string __toString ( ) | ||
return | string | The DB expression. |
---|