我有这个 MySQL
我想转换为条令理解的查询。
SELECT name from users where project = 10 and (classification = 12
or classification is null)
所以我试着把它转化为教义,但它不起作用。
$query->AndWhere('users.classification = :classification');
$query->setParameter(':classification', $classification);
$query->orWhere('users.classification = :classification');
$query->setParameter(':classification', null);
我试过用这个词 $query->expr()
我没有成功
1条答案
按热度按时间qmelpv7a1#
要将多个where语句分组到括号中,可以使用
orx
以及andx
```$queryBuilder->andWhere($queryBuilder->expr()->orX(
'users.classification = :classification',
'users.classification IS NULL'
))
->setParameter(':classification', $classification);
$queryBuilder->andWhere($queryBuilder->expr()->orX(
$queryBuilder->expr()->eq('user.classification', ':classification'),
$queryBuilder->expr()->isNull('users.classification')
))
->setParameter(':classification', $classification);