Skip to content
PHP Ecosystem
Explore

LikeCondition

API reference › yii › db › conditions › LikeCondition

classyii\db\conditions\LikeCondition
ExtendsSimpleCondition
ImplementsConditionInterface
Since2.0.14
Sourceframework/db/conditions/LikeCondition.php

Class LikeCondition represents a LIKE condition.

PropertyTypeDescriptionDefined by
$escapingReplacements protectedarray|null|falseMap of chars to their replacements, false if characters should not be escaped or either null or empty array if escaping is condition builder responsibility. Default: null.LikeCondition
MethodDescriptionDefined by
__construct()LikeCondition
fromArrayDefinition() staticCreates object by array-definition as described in Query Builder – Operator format guide article.LikeCondition
getColumn()SimpleCondition
getEscapingReplacements()LikeCondition
getOperator()SimpleCondition
getValue()SimpleCondition
setEscapingReplacements()This method allows to specify how to escape special characters in the value(s).LikeCondition
protected array|null|false $escapingReplacements = null

Map of chars to their replacements, false if characters should not be escaped or either null or empty array if escaping is condition builder responsibility.

By default it’s set to null.

public function __construct(string $column, string $operator, string[]|string $value)

Parameters

ParameterTypeDescription
$columnstringThe column name.
$operatorstringThe operator to use (e.g. LIKE, NOT LIKE, OR LIKE or OR NOT LIKE)
$valuestring[]|stringSingle value or an array of values that $column should be compared with. If it is an empty array the generated expression will be a false value if operator is LIKE or OR LIKE and empty if operator is NOT LIKE or OR NOT LIKE.
public static function fromArrayDefinition(mixed $operator, mixed $operands): static

Creates object by array-definition as described in Query Builder – Operator format guide article.

Parameters

ParameterTypeDescription
$operatormixedOperator in uppercase.
$operandsmixedArray of corresponding operands

Returns

static

Throws

public function getEscapingReplacements(): array|null|false

Returns

array|null|false

public function setEscapingReplacements(array|null|false $escapingReplacements): mixed

This method allows to specify how to escape special characters in the value(s).

Parameters

ParameterTypeDescription
$escapingReplacementsarray|null|falseAn array of mappings from the special characters to their escaped counterparts. You may use false to indicate the values are already escaped and no escape should be applied, or either null or empty array if escaping is condition builder responsibility. Note that when using an escape mapping (or the third operand is not provided), the values will be automatically enclosed within a pair of percentage characters.

Returns

mixed