gpt4 book ai didi

php - Doctrine2,setParameter 没有按预期工作

转载 作者:行者123 更新时间:2023-11-29 03:20:09 27 4
gpt4 key购买 nike

我有一个看起来像 tihs 的简单查询构建器:

    $qb2 = $this->createQueryBuilder('d')
->select('a.name, c.externalId, c.id, c.name, d.name')
->join('d.urls', 'u')
->distinct('c.externalId')

->join('u.keywords', 'k')
->join('k.adGroup', 'ag')
->join('ag.campaign', 'c')
->join('c.account', 'a')
->where('a.isActive = 1 and c.status = :status and d.name LIKE :domain');

$query2 = $qb2->getQuery();
$query2->setParameter('domain', "'%somedomain%'");
$query2->setParameter('status', 'ENABLED');

它产生以下查询

SELECT
a0_.name AS name_0,
c1_.external_id AS external_id_1,
c1_.id AS id_2,
c1_.name AS name_3,
u2_.name AS name_4
FROM
url_domain u2_
INNER JOIN url_to_domain u4_ ON
u2_.id = u4_.url_domain_id
INNER JOIN url u3_ ON
u3_.id = u4_.url_id
INNER JOIN keyword k5_ ON
u3_.id = k5_.url_id
INNER JOIN ad_group a6_ ON
k5_.ad_group_id = a6_.id
INNER JOIN campaign c1_ ON
a6_.campaign_id = c1_.id
INNER JOIN account a0_ ON
c1_.account_id = a0_.id
WHERE
a0_.is_active = 1 AND c1_.status = ? AND u2_.name LIKE ?

当我像这样使用它时,我从中得到 0 个结果,但是当我把东西放在像这样的双引号中时 "a.isActive = 1 and c.status = 'ENABLED' and d.name LIKE ' %{$somedomain}%'" 我得到了想要的结果我做错了什么?感谢任何帮助

最佳答案

您在错误的地方绑定(bind)了参数。您应该在 调用 getQuery() 之前绑定(bind)它们。这样的事情应该有效:

$qb2 = $this->createQueryBuilder('d')
->select('a.name, c.externalId, c.id, c.name, d.name')
->join('d.urls', 'u')
->distinct('c.externalId')
->join('u.keywords', 'k')
->join('k.adGroup', 'ag')
->join('ag.campaign', 'c')
->join('c.account', 'a')
->where('a.isActive = 1 and c.status = :status and d.name LIKE :domain');
->setParameter('domain', '%'.$some_domain.'%');
->setParameter('status', 'ENABLED');

$query2 = $qb2->getQuery();

关于php - Doctrine2,setParameter 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46639621/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com