類別 yii\db\conditions\BetweenColumnsCondition
繼承關係 | yii\db\conditions\BetweenColumnsCondition |
---|---|
實作介面 | yii\db\conditions\ConditionInterface |
自版本 | 2.0.14 |
原始碼 | https://github.com/yiisoft/yii2/blob/master/framework/db/conditions/BetweenColumnsCondition.php |
Class BetweenColumnCondition 代表一個 BETWEEN
條件,值介於兩個欄位之間。例如:
new BetweenColumnsCondition(42, 'BETWEEN', 'min_value', 'max_value')
// Will be build to:
// 42 BETWEEN min_value AND max_value
以及更複雜的範例:
new BetweenColumnsCondition(
new Expression('NOW()'),
'NOT BETWEEN',
(new Query)->select('time')->from('log')->orderBy('id ASC')->limit(1),
'update_time'
);
// Will be built to:
// NOW() NOT BETWEEN (SELECT time FROM log ORDER BY id ASC LIMIT 1) AND update_time
公開方法
方法詳情
使用 BETWEEN
運算子建立條件。
public void __construct ( $value, $operator, $intervalStartColumn, $intervalEndColumn ) | ||
$value | ||
$operator | string |
要使用的運算子 (例如 |
$intervalStartColumn | string|yii\db\ExpressionInterface |
作為區間起始的欄位名稱或表達式 |
$intervalEndColumn | string|yii\db\ExpressionInterface |
作為區間結束的欄位名稱或表達式 |
public function __construct($value, $operator, $intervalStartColumn, $intervalEndColumn)
{
$this->value = $value;
$this->operator = $operator;
$this->intervalStartColumn = $intervalStartColumn;
$this->intervalEndColumn = $intervalEndColumn;
}
依照 查詢語法建構器 – 運算子格式 指南文章中描述的陣列定義建立物件。
public static $this fromArrayDefinition ( $operator, $operands ) | ||
$operator | string |
大寫的運算子。 |
$operands | array |
對應運算元的陣列 |
擲出 | yii\base\InvalidArgumentException |
如果給定的運算元數量錯誤。 |
---|
public static function fromArrayDefinition($operator, $operands)
{
if (!isset($operands[0], $operands[1], $operands[2])) {
throw new InvalidArgumentException("Operator '$operator' requires three operands.");
}
return new static($operands[0], $operator, $operands[1], $operands[2]);
}
public string|yii\db\ExpressionInterface|yii\db\Query getIntervalEndColumn ( ) |
public function getIntervalEndColumn()
{
return $this->intervalEndColumn;
}
public string|yii\db\ExpressionInterface|yii\db\Query getIntervalStartColumn ( ) |
public function getIntervalStartColumn()
{
return $this->intervalStartColumn;
}
註冊 或 登入 以發表評論。