php SQL查询需要在ORM中重写[关闭]

m4pnthwp  于 2023-05-05  发布在  PHP
关注(0)|答案(1)|浏览(69)

已关闭,此问题需要更focused。目前不接受答复。
**想改善这个问题吗?**更新问题,使其仅通过editing this post关注一个问题。

22小时前关门了。
Improve this question
如果idt1表中,且其状态不等于"performed",则发出错误。
我用SQL格式写了这个查询,你需要在php中用orm重写它

select id, status
from t1
where external_ref in (
                       'id1',
'id2',
'id3'
    )
  and not status = 'performed'
ql3eal8s

ql3eal8s1#

这是通过eloquant ORM编写的,

$result = DB::table('t1')
                ->select('id', 'status')
                ->whereIn('external_ref', ['id1', 'id2', 'id3'])
                ->where('status', '<>', 'performed')
                ->get();

通过doctrine

$queryBuilder = $entityManager->createQueryBuilder();
$queryBuilder->select('t.id, t.status')
             ->from('App\Entity\t1', 't')
             ->where($queryBuilder->expr()->in('t.externalRef', ['id1', 'id2', 'id3']))
             ->andWhere($queryBuilder->expr()->neq('t.status', 'performed'));

$results = $queryBuilder->getQuery()->getResult();

相关问题