Conditions¶
Conditions are used in WHERE
and HAVING
clauses. A basic condition is expressed as expression
operator
value
.
Simple condition¶
You can construct a simple condition via QueryBuilder->condition():
Output
Condition builder¶
For more complex conditions you should use Blrf\Dbal\Query\ConditionBuilder
.
You can start condition builder via QueryBuilder by providing callback function to where()
or having()
method:
Output
You can use condition builder to create groups of conditions of two possible types: AND
and OR
.
<?php
$queryBuilder->where(
fn(Blrf\Dbal\Query\ConditionBuilder $cb) => $cb->or(
$cb->and(
$cb->eq('isbn13'),
$cb->eq('language_id'),
),
$cb->eq('title')
)
);
Will create SQL condition:
Operators¶
There are many predefined operators (methods) available:
- eq(): Equal
=
- neq(): Not equal
<>
- lt(): Less than
<
- lte(): Less than or equal
<=
- gt(): Greater than
>
- gte(): Greater than or equal
>=
- isNull():
IS NULL
- isNotNull():
IS NOT NULL
- like():
LIKE
- notLike():
NOT LIKE
Note
More should be added (LIKE, NOT LIKE, IN, NOT IN, ...)
And you may also use condition()
method to construct any condition.