How to concatenate fields in select statements using Doctrine
doctrine-orm
Solution
We cannot send three arguments here, but we can do it like this,
$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();
This part is that what you want:
$qb_1->select( "reprt_abs.id" ) ->addSelect( "CONCAT( CONCAT(reporter.firstname, ' '), reporter.lastname)" )
Following is the output at my side:
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)
Problem
I'm wondering how to concatenate two fields in DQL select statement with some literal between. I have this for now but no luck... ``` $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) ; ```