我想知道如何将 DQL select 语句中的两个字段与一些文字连接起来。
我现在有这个,但没有运气...
$qb
->select('season.id, concat(competition.name, '-',season.name) AS specs')
->leftJoin('season.competition', 'competition')
->where('season.name LIKE :q')
->setParameter('q', '%'.$q.'%')
->setMaxResults($p)
;
最佳答案
我们不能在这里发送三个参数,但我们可以这样做,
$em = \Zend_Registry::get('em');
$qb_1 = $em->createQueryBuilder();
$q_1 = $qb_1->select( "reprt_abs.id" )
->addSelect( "CONCAT( CONCAT(reporter.firstname, ' '), reporter.lastname)" )
->from( '\Entities\report_abuse', 'reprt_abs' )
->leftJoin( 'reprt_abs.User', 'reporter' )
->getQuery()->getResult();
这部分是你想要的:
$qb_1->select( "reprt_abs.id" ) ->addSelect( "CONCAT( CONCAT(reporter.firstname, ' '), reporter.lastname)" )
以下是我这边的输出:
array (size=19)
0 =>
array (size=2)
'id' => int 1
1 => string 'Jaskaran Singh' (length=14)
1 =>
array (size=2)
'id' => int 9
1 => string 'Harsimer Kaur' (length=14)
2 =>
array (size=2)
'id' => int 12
1 => string 'Jaskaran Singh' (length=14)
3 =>
array (size=2)
'id' => int 16
1 => string 'Jaskaran Singh' (length=14)
4 =>
array (size=2)
'id' => int 19
1 => string 'Jaskaran Singh' (length=14)
5 =>
array (size=2)
'id' => int 4
1 => string 'shilpi jaiswal' (length=14)
关于doctrine-orm - 如何使用Doctrine连接select语句中的字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28629100/