Yii2 framework backup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.9 KiB

13 years ago
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
13 years ago
* @license http://www.yiiframework.com/license/
*/
namespace yii\db;
13 years ago
/**
* Expression represents a DB expression that does not need escaping or quoting.
*
13 years ago
* 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,
*
* ```php
13 years ago
* $expression = new Expression('NOW()');
* $now = (new \yii\db\Query)->select($expression)->scalar(); // SELECT NOW();
* echo $now; // prints the current date
* ```
13 years ago
*
* Expression objects are mainly created for passing raw SQL expressions to methods of
* [[Query]], [[ActiveQuery]], and related classes.
*
13 years ago
* An expression can also be bound with parameters specified via [[params]].
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class Expression extends \yii\base\BaseObject implements ExpressionInterface
13 years ago
{
/**
* @var string the DB expression
*/
public $expression;
/**
* @var array 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 $params = [];
13 years ago
/**
* Constructor.
* @param string $expression the DB expression
* @param array $params parameters
* @param array $config name-value pairs that will be used to initialize the object properties
*/
public function __construct($expression, $params = [], $config = [])
{
$this->expression = $expression;
$this->params = $params;
parent::__construct($config);
}
13 years ago
/**
* String magic method.
* @return string the DB expression.
*/
public function __toString()
{
return $this->expression;
}
}