Doctrine orm 如何使用条令连接select语句中的字段

Doctrine orm 如何使用条令连接select语句中的字段,doctrine-orm,Doctrine Orm,我想知道如何在DQL select语句中连接两个字段,并在它们之间加上一些文字 我现在有这个,但运气不好 $qb ->select('season.id, concat(competition.name, '-',season.name) AS specs') ->leftJoin('season.competition', 'competition') ->where('season.name LIKE

我想知道如何在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->选择(“报告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)

我在MySQL数据库PDO平台上的Doctrine 2.4+中使用的解决方案:

$concat = new Query\Expr\Func('CONCAT', $name[$k]);
$concat .= ' as ' . $k;
$concat = str_replace(',', ',\' \',', $concat);
$this->query->addSelect($concat);
因此,$name[$k]是一个字段数组,可以任意多个。然后用str_replace在字段之间添加一些间距$k是concat字段的名称,因此$concat的结果是

"CONCAT(p.email,' ', h.phoneNumber,' ', p.officialName) as details"

我努力把工作做好。你有什么问题?对我来说,3+
CONCAT
arguments有效(原则2.5.4)。我有不同的问题-它不能在
CONCAT
中使用引号(
),只能使用撇号(
)。例如
CONCAT(“a”,“b”)
不起作用。但它不应该是大写。