Class Yiisoft\Db\Query\Query
| Inheritance | Yiisoft\Db\Query\Query |
|---|---|
| Implements | Yiisoft\Db\Query\QueryInterface |
Represents a SELECT SQL statement in a way that's independent of DBMS.
Provides a set of methods to ease the specification of different clauses in a SELECT statement.
You can chain these methods together.
By calling {@see \Yiisoft\Db\Query\createCommand()}, you can get a {@see \Yiisoft\Db\Command\CommandInterface} instance which can be further used to perform/execute the DB query in a database.
For example,
$query = new Query;
// compose the query
$query->select('id, name')->from('user')->limit(10);
// build and execute the query
$rows = $query->all();
// alternatively, you can create DB command and execute it
$command = $query->createCommand();
// $command->sql returns the actual SQL
$rows = $command->queryAll();
Query internally uses the {@see \Yiisoft\Db\QueryBuilder\AbstractQueryBuilder} class to generate the SQL statement.
Protected Properties
Public Methods
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| index() | Yiisoft\Db\Query\Query | |
| queryScalar() | Queries a scalar value by setting {@see select()} first. | Yiisoft\Db\Query\Query |
Property Details
Method Details
| public mixed __construct ( Yiisoft\Db\Connection\ConnectionInterface $db ) | ||
| $db | Yiisoft\Db\Connection\ConnectionInterface | |
public function __construct(protected ConnectionInterface $db) {}
| public Yiisoft\Db\Query\Query addFor ( string|array|null $value ) | ||
| $value | string|array|null | |
public function addFor(string|array|null $value): static
{
if ($value === null) {
return $this;
}
if (is_array($value)) {
$this->for = [...$this->for, ...$value];
return $this;
}
$this->for[] = $value;
return $this;
}
| public Yiisoft\Db\Query\Query addGroupBy ( array|string|Yiisoft\Db\Expression\ExpressionInterface $columns ) | ||
| $columns | array|string|Yiisoft\Db\Expression\ExpressionInterface | |
public function addGroupBy(array|string|ExpressionInterface $columns): static
{
if ($columns instanceof ExpressionInterface) {
$columns = [$columns];
} elseif (!is_array($columns)) {
/** @var string[] */
$columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY);
}
if ($this->groupBy === []) {
$this->groupBy = $columns;
} else {
$this->groupBy = array_merge($this->groupBy, $columns);
}
return $this;
}
| public Yiisoft\Db\Query\Query addOrderBy ( array|string|Yiisoft\Db\Expression\ExpressionInterface $columns ) | ||
| $columns | array|string|Yiisoft\Db\Expression\ExpressionInterface | |
public function addOrderBy(array|string|ExpressionInterface $columns): static
{
$columns = $this->normalizeOrderBy($columns);
if ($this->orderBy === []) {
$this->orderBy = $columns;
} else {
$this->orderBy = array_merge($this->orderBy, $columns);
}
return $this;
}
| public Yiisoft\Db\Query\Query addParams ( array $params ) | ||
| $params | array | |
public function addParams(array $params): static
{
if (empty($params)) {
return $this;
}
if (empty($this->params)) {
$this->params = $params;
return $this;
}
if (is_int(key($params))) {
array_push($this->params, ...$params);
return $this;
}
$this->params = [...$this->params, ...$params];
return $this;
}
public function addSelect(array|bool|float|int|string|ExpressionInterface $columns): static
{
if ($this->select === []) {
return $this->select($columns);
}
$this->select = array_merge($this->select, $this->normalizeSelect($columns));
return $this;
}
| public Yiisoft\Db\Query\Query addWithQuery ( Yiisoft\Db\Query\QueryInterface|string $query, Yiisoft\Db\Expression\ExpressionInterface|string $alias, boolean $recursive = false ) | ||
| $query | Yiisoft\Db\Query\QueryInterface|string | |
| $alias | Yiisoft\Db\Expression\ExpressionInterface|string | |
| $recursive | boolean | |
public function addWithQuery(
QueryInterface|string $query,
ExpressionInterface|string $alias,
bool $recursive = false,
): static {
$this->withQueries[] = new WithQuery($query, $alias, $recursive);
return $this;
}
| public array all ( ) |
public function all(): array
{
if ($this->emulateExecution === true) {
return [];
}
return $this->index($this->createCommand()->queryAll());
}
| public Yiisoft\Db\Query\Query andFilterCompare ( string $column, string|null $value, string $defaultOperator = '=' ) | ||
| $column | string | |
| $value | string|null | |
| $defaultOperator | string | |
public function andFilterCompare(string $column, ?string $value, string $defaultOperator = '='): static
{
$operator = $defaultOperator;
if (preg_match('/^(<>|>=|>|<=|<|=)/', (string) $value, $matches)) {
$operator = $matches[1];
$value = substr((string) $value, strlen($operator));
}
return $this->andFilterWhere([$operator, $column, $value]);
}
| public Yiisoft\Db\Query\Query andFilterHaving ( array $condition ) | ||
| $condition | array | |
public function andFilterHaving(array $condition): static
{
$condition = $this->filterCondition($condition);
if ($condition !== []) {
$this->andHaving($condition);
}
return $this;
}
| public Yiisoft\Db\Query\Query andFilterWhere ( array $condition ) | ||
| $condition | array | |
public function andFilterWhere(array $condition): static
{
$condition = $this->filterCondition($condition);
if ($condition !== []) {
$this->andWhere($condition);
}
return $this;
}
| public Yiisoft\Db\Query\Query andHaving ( array|string|Yiisoft\Db\Expression\ExpressionInterface $condition, array $params = [] ) | ||
| $condition | array|string|Yiisoft\Db\Expression\ExpressionInterface | |
| $params | array | |
public function andHaving(array|string|ExpressionInterface $condition, array $params = []): static
{
if ($this->having === null) {
$this->having = $condition;
} elseif (
is_array($this->having)
&& isset($this->having[0])
&& strcasecmp((string) $this->having[0], 'and') === 0
) {
$this->having[] = $condition;
} else {
$this->having = ['and', $this->having, $condition];
}
$this->addParams($params);
return $this;
}
| public Yiisoft\Db\Query\Query andWhere ( mixed $condition, array $params = [] ) | ||
| $condition | mixed | |
| $params | array | |
public function andWhere($condition, array $params = []): static
{
if ($this->where === null) {
$this->where = $condition;
} elseif (
is_array($this->where)
&& isset($this->where[0])
&& strcasecmp((string) $this->where[0], 'and') === 0
) {
$this->where[] = $condition;
} else {
$this->where = ['and', $this->where, $condition];
}
$this->addParams($params);
return $this;
}
| public integer|float|string|null average ( string $sql ) | ||
| $sql | string | |
public function average(string $sql): int|float|string|null
{
return match ($this->emulateExecution) {
true => null,
false => is_numeric($avg = $this->queryScalar("AVG($sql)")) ? $avg : null,
};
}
| public Yiisoft\Db\Query\BatchQueryResultInterface batch ( integer $batchSize = 100 ) | ||
| $batchSize | integer | |
public function batch(int $batchSize = 100): BatchQueryResultInterface
{
return $this->db
->createBatchQueryResult($this)
->batchSize($batchSize);
}
| public array column ( ) |
public function column(): array
{
if ($this->emulateExecution) {
return [];
}
if ($this->indexBy === null) {
return $this->createCommand()->queryColumn();
}
if (is_string($this->indexBy)) {
if (count($this->select) === 1) {
if (!str_contains($this->indexBy, '.') && count($tables = $this->getTablesUsedInFrom()) > 0) {
$this->select[] = key($tables) . '.' . $this->indexBy;
} else {
$this->select[] = $this->indexBy;
}
}
$rows = $this->createCommand()->queryAll();
if (empty($rows)) {
return [];
}
if (($dotPos = strpos($this->indexBy, '.')) === false) {
$column = $this->indexBy;
} else {
$column = substr($this->indexBy, $dotPos + 1);
}
return array_column($rows, key(current($rows)), $column);
}
$rows = $this->createCommand()->queryAll();
if (empty($rows)) {
return [];
}
return array_combine(array_map($this->indexBy, $rows), array_column($rows, key(current($rows))));
}
| public integer|string count ( string $sql = '*' ) | ||
| $sql | string | |
public function count(string $sql = '*'): int|string
{
/** @var int|string|null $count */
$count = $this->queryScalar("COUNT($sql)");
if ($count === null) {
return 0;
}
/** @psalm-var non-negative-int|string */
return $count <= PHP_INT_MAX ? (int) $count : $count;
}
| public Yiisoft\Db\Command\CommandInterface createCommand ( ) |
public function createCommand(): CommandInterface
{
[$sql, $params] = $this->db->getQueryBuilder()->build($this);
return $this->db->createCommand($sql, $params)->withPhpTypecasting($this->typecasting);
}
| public Yiisoft\Db\Query\Query distinct ( boolean $value = true ) | ||
| $value | boolean | |
public function distinct(bool $value = true): static
{
$this->distinct = $value;
return $this;
}
| public Yiisoft\Db\Query\DataReaderInterface each ( ) |
public function each(): DataReaderInterface
{
return $this->createCommand()
->query()
->indexBy($this->indexBy)
->resultCallback($this->resultCallback !== null ? $this->callResultCallbackOnOne(...) : null);
}
| public Yiisoft\Db\Query\Query emulateExecution ( boolean $value = true ) | ||
| $value | boolean | |
public function emulateExecution(bool $value = true): static
{
$this->emulateExecution = $value;
return $this;
}
| public boolean exists ( ) |
public function exists(): bool
{
if ($this->emulateExecution) {
return false;
}
$command = $this->createCommand();
$params = $command->getParams();
$command->setSql($this->db->getQueryBuilder()->selectExists($command->getSql()));
$command->bindValues($params);
return (bool) $command->queryScalar();
}
| public Yiisoft\Db\Query\Query filterHaving ( array $condition ) | ||
| $condition | array | |
public function filterHaving(array $condition): static
{
$condition = $this->filterCondition($condition);
if ($condition !== []) {
$this->having($condition);
}
return $this;
}
| public Yiisoft\Db\Query\Query filterWhere ( array $condition ) | ||
| $condition | array | |
public function filterWhere(array $condition): static
{
$condition = $this->filterCondition($condition);
if ($condition !== []) {
$this->where($condition);
}
return $this;
}
| public Yiisoft\Db\Query\Query for ( string|array|null $value ) | ||
| $value | string|array|null | |
public function for(string|array|null $value): static
{
if ($this->for !== []) {
throw new LogicException('The `FOR` part was set earlier. Use the `setFor()` or `addFor()` method.');
}
return $this->setFor($value);
}
| public Yiisoft\Db\Query\Query from ( array|Yiisoft\Db\Expression\ExpressionInterface|string $tables ) | ||
| $tables | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
public function from(array|ExpressionInterface|string $tables): static
{
$this->from = DbArrayHelper::normalizeExpressions($tables);
return $this;
}
| public string|array|Yiisoft\Db\Expression\ExpressionInterface|null getHaving ( ) |
public function getHaving(): string|array|ExpressionInterface|null
{
return $this->having;
}
| public Closure|string|null getIndexBy ( ) |
public function getIndexBy(): Closure|string|null
{
return $this->indexBy;
}
| public Yiisoft\Db\Expression\ExpressionInterface|integer|null getLimit ( ) |
public function getLimit(): ExpressionInterface|int|null
{
return $this->limit;
}
| public Yiisoft\Db\Expression\ExpressionInterface|integer|null getOffset ( ) |
public function getOffset(): ExpressionInterface|int|null
{
return $this->offset;
}
| public Closure|null getResultCallback ( ) |
public function getResultCallback(): ?Closure
{
return $this->resultCallback;
}
| public string|null getSelectOption ( ) |
public function getSelectOption(): ?string
{
return $this->selectOption;
}
| public array getTablesUsedInFrom ( ) |
public function getTablesUsedInFrom(): array
{
return $this->db->getQuoter()->cleanUpTableNames($this->from);
}
| public array|string|Yiisoft\Db\Expression\ExpressionInterface|null getWhere ( ) |
public function getWhere(): array|string|ExpressionInterface|null
{
return $this->where;
}
| public array getWithQueries ( ) |
public function getWithQueries(): array
{
return $this->withQueries;
}
| public Yiisoft\Db\Query\Query groupBy ( array|string|Yiisoft\Db\Expression\ExpressionInterface $columns ) | ||
| $columns | array|string|Yiisoft\Db\Expression\ExpressionInterface | |
public function groupBy(array|string|ExpressionInterface $columns): static
{
$this->groupBy = DbArrayHelper::normalizeExpressions($columns);
return $this;
}
| public Yiisoft\Db\Query\Query having ( array|Yiisoft\Db\Expression\ExpressionInterface|string|null $condition, array $params = [] ) | ||
| $condition | array|Yiisoft\Db\Expression\ExpressionInterface|string|null | |
| $params | array | |
public function having(array|ExpressionInterface|string|null $condition, array $params = []): static
{
if ($this->having === null) {
$this->having = $condition;
} else {
throw new LogicException('The `having` condition was set earlier. Use the `setHaving()`, `andHaving()` or `orHaving()` method.');
}
$this->addParams($params);
return $this;
}
| protected array[]|object[] index ( array $rows ) | ||
| $rows | array | |
protected function index(array $rows): array
{
return DbArrayHelper::index($rows, $this->indexBy, $this->resultCallback);
}
| public Yiisoft\Db\Query\Query indexBy ( Closure|string|null $column ) | ||
| $column | Closure|string|null | |
public function indexBy(Closure|string|null $column): static
{
$this->indexBy = $column;
return $this;
}
| public Yiisoft\Db\Query\Query innerJoin ( array|Yiisoft\Db\Expression\ExpressionInterface|string $table, array|Yiisoft\Db\Expression\ExpressionInterface|string $on = '', array $params = [] ) | ||
| $table | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $on | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $params | array | |
public function innerJoin(
array|ExpressionInterface|string $table,
array|ExpressionInterface|string $on = '',
array $params = [],
): static {
$this->joins[] = ['INNER JOIN', $table, $on];
return $this->addParams($params);
}
| public Yiisoft\Db\Query\Query join ( string $type, array|Yiisoft\Db\Expression\ExpressionInterface|string $table, array|Yiisoft\Db\Expression\ExpressionInterface|string $on = '', array $params = [] ) | ||
| $type | string | |
| $table | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $on | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $params | array | |
public function join(
string $type,
array|ExpressionInterface|string $table,
array|ExpressionInterface|string $on = '',
array $params = [],
): static {
$this->joins[] = [$type, $table, $on];
return $this->addParams($params);
}
| public Yiisoft\Db\Query\Query leftJoin ( array|Yiisoft\Db\Expression\ExpressionInterface|string $table, array|Yiisoft\Db\Expression\ExpressionInterface|string $on = '', array $params = [] ) | ||
| $table | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $on | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $params | array | |
public function leftJoin(
array|ExpressionInterface|string $table,
array|ExpressionInterface|string $on = '',
array $params = [],
): static {
$this->joins[] = ['LEFT JOIN', $table, $on];
return $this->addParams($params);
}
| public Yiisoft\Db\Query\Query limit ( Yiisoft\Db\Expression\ExpressionInterface|integer|null $limit ) | ||
| $limit | Yiisoft\Db\Expression\ExpressionInterface|integer|null | |
public function limit(ExpressionInterface|int|null $limit): static
{
$this->limit = $limit;
return $this;
}
| public integer|float|string|null max ( string $sql ) | ||
| $sql | string | |
public function max(string $sql): int|float|string|null
{
$max = $this->queryScalar("MAX($sql)");
return is_numeric($max) ? $max : null;
}
| public integer|float|string|null min ( string $sql ) | ||
| $sql | string | |
public function min(string $sql): int|float|string|null
{
$min = $this->queryScalar("MIN($sql)");
return is_numeric($min) ? $min : null;
}
| public Yiisoft\Db\Query\Query offset ( Yiisoft\Db\Expression\ExpressionInterface|integer|null $offset ) | ||
| $offset | Yiisoft\Db\Expression\ExpressionInterface|integer|null | |
public function offset(ExpressionInterface|int|null $offset): static
{
$this->offset = $offset;
return $this;
}
| public array|object|null one ( ) |
public function one(): array|object|null
{
if ($this->emulateExecution) {
return null;
}
$row = $this->createCommand()->queryOne();
if ($this->resultCallback === null || $row === null) {
return $row;
}
return $this->callResultCallbackOnOne($row);
}
| public Yiisoft\Db\Query\Query orFilterHaving ( array $condition ) | ||
| $condition | array | |
public function orFilterHaving(array $condition): static
{
$condition = $this->filterCondition($condition);
if ($condition !== []) {
$this->orHaving($condition);
}
return $this;
}
| public Yiisoft\Db\Query\Query orFilterWhere ( array $condition ) | ||
| $condition | array | |
public function orFilterWhere(array $condition): static
{
$condition = $this->filterCondition($condition);
if ($condition !== []) {
$this->orWhere($condition);
}
return $this;
}
| public Yiisoft\Db\Query\Query orHaving ( array|string|Yiisoft\Db\Expression\ExpressionInterface $condition, array $params = [] ) | ||
| $condition | array|string|Yiisoft\Db\Expression\ExpressionInterface | |
| $params | array | |
public function orHaving(array|string|ExpressionInterface $condition, array $params = []): static
{
if ($this->having === null) {
$this->having = $condition;
} else {
$this->having = ['or', $this->having, $condition];
}
$this->addParams($params);
return $this;
}
| public Yiisoft\Db\Query\Query orWhere ( array|string|Yiisoft\Db\Expression\ExpressionInterface $condition, array $params = [] ) | ||
| $condition | array|string|Yiisoft\Db\Expression\ExpressionInterface | |
| $params | array | |
public function orWhere(array|string|ExpressionInterface $condition, array $params = []): static
{
if ($this->where === null) {
$this->where = $condition;
} else {
$this->where = ['or', $this->where, $condition];
}
$this->addParams($params);
return $this;
}
| public Yiisoft\Db\Query\Query orderBy ( array|string|Yiisoft\Db\Expression\ExpressionInterface $columns ) | ||
| $columns | array|string|Yiisoft\Db\Expression\ExpressionInterface | |
public function orderBy(array|string|ExpressionInterface $columns): static
{
$this->orderBy = $this->normalizeOrderBy($columns);
return $this;
}
| public Yiisoft\Db\Query\Query params ( array $params ) | ||
| $params | array | |
public function params(array $params): static
{
$this->params = $params;
return $this;
}
| public Yiisoft\Db\Query\QueryInterface prepare ( Yiisoft\Db\QueryBuilder\QueryBuilderInterface $builder ) | ||
| $builder | Yiisoft\Db\QueryBuilder\QueryBuilderInterface | |
public function prepare(QueryBuilderInterface $builder): QueryInterface
{
return $this;
}
Queries a scalar value by setting {@see select()} first.
Restores the value of select to make this query reusable.
| protected boolean|integer|string|float|null queryScalar ( string|Yiisoft\Db\Expression\ExpressionInterface $selectExpression ) | ||
| $selectExpression | string|Yiisoft\Db\Expression\ExpressionInterface | |
| throws | Yiisoft\Db\Exception\Exception | |
|---|---|---|
| throws | InvalidArgumentException | |
| throws | Yiisoft\Db\Exception\InvalidConfigException | |
| throws | Yiisoft\Db\Exception\NotSupportedException | |
| throws | Throwable | |
protected function queryScalar(string|ExpressionInterface $selectExpression): bool|int|string|float|null
{
if ($this->emulateExecution) {
return null;
}
if (
!$this->distinct
&& empty($this->groupBy)
&& empty($this->having)
&& empty($this->union)
) {
$select = $this->select;
$order = $this->orderBy;
$limit = $this->limit;
$offset = $this->offset;
$this->select = [$selectExpression];
$this->orderBy = [];
$this->limit = null;
$this->offset = null;
$command = $this->createCommand();
$this->select = $select;
$this->orderBy = $order;
$this->limit = $limit;
$this->offset = $offset;
return $command->queryScalar();
}
$query = (new self($this->db))->select($selectExpression)->from(['c' => $this]);
[$sql, $params] = $this->db->getQueryBuilder()->build($query);
$command = $this->db->createCommand($sql, $params);
return $command->queryScalar();
}
| public Yiisoft\Db\Query\Query resultCallback ( Closure|null $resultCallback ) | ||
| $resultCallback | Closure|null | |
public function resultCallback(?Closure $resultCallback): static
{
$this->resultCallback = $resultCallback;
return $this;
}
| public Yiisoft\Db\Query\Query rightJoin ( array|Yiisoft\Db\Expression\ExpressionInterface|string $table, array|Yiisoft\Db\Expression\ExpressionInterface|string $on = '', array $params = [] ) | ||
| $table | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $on | array|Yiisoft\Db\Expression\ExpressionInterface|string | |
| $params | array | |
public function rightJoin(
array|ExpressionInterface|string $table,
array|ExpressionInterface|string $on = '',
array $params = [],
): static {
$this->joins[] = ['RIGHT JOIN', $table, $on];
return $this->addParams($params);
}
| public boolean|integer|string|float|null scalar ( ) |
public function scalar(): bool|int|string|float|null
{
return match ($this->emulateExecution) {
true => null,
false => $this->createCommand()->queryScalar(),
};
}
| public Yiisoft\Db\Query\Query select ( array|boolean|float|integer|string|Yiisoft\Db\Expression\ExpressionInterface $columns, string|null $option = null ) | ||
| $columns | array|boolean|float|integer|string|Yiisoft\Db\Expression\ExpressionInterface | |
| $option | string|null | |
public function select(array|bool|float|int|string|ExpressionInterface $columns, ?string $option = null): static
{
$this->select = $this->normalizeSelect($columns);
$this->selectOption = $option;
return $this;
}
| public Yiisoft\Db\Query\Query selectOption ( string|null $value ) | ||
| $value | string|null | |
public function selectOption(?string $value): static
{
$this->selectOption = $value;
return $this;
}
| public Yiisoft\Db\Query\Query setFor ( array|string|null $value ) | ||
| $value | array|string|null | |
public function setFor(array|string|null $value): static
{
if ($value === null) {
$this->for = [];
return $this;
}
$this->for = (array) $value;
return $this;
}
| public Yiisoft\Db\Query\Query setHaving ( array|Yiisoft\Db\Expression\ExpressionInterface|string|null $condition, array $params = [] ) | ||
| $condition | array|Yiisoft\Db\Expression\ExpressionInterface|string|null | |
| $params | array | |
public function setHaving(array|ExpressionInterface|string|null $condition, array $params = []): static
{
$this->having = $condition;
$this->addParams($params);
return $this;
}
| public Yiisoft\Db\Query\Query setJoins ( array $value ) | ||
| $value | array | |
public function setJoins(array $value): static
{
$this->joins = $value;
return $this;
}
| public Yiisoft\Db\Query\Query setUnions ( array $value ) | ||
| $value | array | |
public function setUnions(array $value): static
{
$this->union = $value;
return $this;
}
| public Yiisoft\Db\Query\Query setWhere ( array|string|Yiisoft\Db\Expression\ExpressionInterface|null $condition, array $params = [] ) | ||
| $condition | array|string|Yiisoft\Db\Expression\ExpressionInterface|null | |
| $params | array | |
public function setWhere(array|string|ExpressionInterface|null $condition, array $params = []): static
{
$this->where = $condition;
$this->addParams($params);
return $this;
}
| public boolean shouldEmulateExecution ( ) |
public function shouldEmulateExecution(): bool
{
return $this->emulateExecution;
}
| public integer|float|string|null sum ( string $sql ) | ||
| $sql | string | |
public function sum(string $sql): int|float|string|null
{
return match ($this->emulateExecution) {
true => null,
false => is_numeric($sum = $this->queryScalar("SUM($sql)")) ? $sum : null,
};
}
| public Yiisoft\Db\Query\Query union ( Yiisoft\Db\Query\QueryInterface|string $sql, boolean $all = false ) | ||
| $sql | Yiisoft\Db\Query\QueryInterface|string | |
| $all | boolean | |
public function union(QueryInterface|string $sql, bool $all = false): static
{
$this->union[] = ['query' => $sql, 'all' => $all];
return $this;
}
| public Yiisoft\Db\Query\Query where ( array|string|Yiisoft\Db\Expression\ExpressionInterface|null $condition, array $params = [] ) | ||
| $condition | array|string|Yiisoft\Db\Expression\ExpressionInterface|null | |
| $params | array | |
public function where(array|string|ExpressionInterface|null $condition, array $params = []): static
{
if ($this->where !== null) {
throw new LogicException(
'The `where` condition was set earlier. Use the `setWhere()`, `andWhere()` or `orWhere()` method.',
);
}
$this->where = $condition;
$this->addParams($params);
return $this;
}
| public Yiisoft\Db\Query\Query withQueries ( Yiisoft\Db\Query\WithQuery $queries ) | ||
| $queries | Yiisoft\Db\Query\WithQuery | |
public function withQueries(WithQuery ...$queries): static
{
$this->withQueries = $queries;
return $this;
}
| public Yiisoft\Db\Query\Query withQuery ( Yiisoft\Db\Query\QueryInterface|string $query, Yiisoft\Db\Expression\ExpressionInterface|string $alias, boolean $recursive = false ) | ||
| $query | Yiisoft\Db\Query\QueryInterface|string | |
| $alias | Yiisoft\Db\Expression\ExpressionInterface|string | |
| $recursive | boolean | |
public function withQuery(
QueryInterface|string $query,
ExpressionInterface|string $alias,
bool $recursive = false,
): static {
$this->withQueries = [new WithQuery($query, $alias, $recursive)];
return $this;
}
| public Yiisoft\Db\Query\Query withTypecasting ( boolean $typecasting = true ) | ||
| $typecasting | boolean | |
public function withTypecasting(bool $typecasting = true): static
{
$new = clone $this;
$new->typecasting = $typecasting;
return $new;
}
Signup or Login in order to comment.