php – Doctrine QueryBuilder和concat问题
发布时间:2020-12-13 13:16:39 所属栏目:PHP教程 来源:网络整理
导读:我有以下代码,它依赖于Doctrine的QueryBuilder API来生成DQL状态. class PlayerRepository extends EntityRepository{ public function findByPartialNameMatch($trainer,$fullName) { $qb = $this-createQueryBuilder('tp'); $qb-innerJoin('tp.player','p'
我有以下代码,它依赖于Doctrine的QueryBuilder API来生成DQL状态.
class PlayerRepository extends EntityRepository { public function findByPartialNameMatch($trainer,$fullName) { $qb = $this->createQueryBuilder('tp'); $qb->innerJoin('tp.player','p') ->where($qb->expr()->andX( $qb->expr()->orX( $qb->expr()->like( $qb->expr()->concat('p.firstName',$qb->expr()->concat(' ','p.lastName')),$qb->expr()->literal($fullName.'%') ),$qb->expr()->like( $qb->expr()->concat('p.lastName','p.firstName')),$qb->expr()->literal($fullName.'%') ) ),$qb->expr()->eq('tp.trainer','?1') ) ) ->groupBy('p.id') ->orderBy('p.lastName','ASC') ->orderBy('p.firstName','ASC') ->setParameter(1,$trainer); return $qb->getQuery()->getResult(); } } 当我运行它时,Symfony2抛出以下错误消息: [Syntax Error] line 0,col 123: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression,got ',' 查看堆栈跟踪,显示以下内容: at QueryException ::syntaxError ('line 0,col 123: Error: Expected StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression,'') in D:WorkvendordoctrinelibDoctrineORMQueryParser.php at line 396 -+ at Parser ->syntaxError ('StateFieldPathExpression | string | InputParameter | FunctionsReturningStrings | AggregateExpression') in D:WorkvendordoctrinelibDoctrineORMQueryParser.php at line 2391 -+ at Parser ->StringPrimary () in D:WorkvendordoctrinelibDoctrineORMQueryASTFunctionsConcatFunction.php at line 60 -+ at ConcatFunction ->parse (object(Parser)) in D:WorkvendordoctrinelibDoctrineORMQueryParser.php at line 2852 - 从上面可以看出,这个问题与concat helper函数有某种关系,并且该函数需要枚举输入,但不知何故(?)收到了一个逗号(,). 上面的代码有什么问题?搜索时间无法解决问题. 谢谢你的帮助!
问题在于这一部分:
$qb->expr()->concat(' ','p.lastName') 你不能只是放空间,因为教义期望这里有一些识别者.试试这个: $qb->expr()->concat($qb->expr()->literal(' '),'p.lastName') (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |