是什么导致预期的文字错误?

问题描述 投票:-1回答:1

我有一个语法错误的查询。这是错误!

string(63)“ [语法错误]第0行,列57:错误:预期文字,有'd'“

public function getDomain(string $country)
{
    try {
        return $this->createQueryBuilder('d')
            ->where(':country NOT IN (d.blocked_countries)')
            ->setParameter('country', $country)
            ->setMaxResults(1)
            ->getQuery()
            ->getSingleResult()
            ;
    } catch (\Exception $exception) {
        return $exception->getMessage();
    }
}
php symfony symfony4
1个回答
0
投票

在这种情况下,我们无法应用IN运算符,因为主义将array type作为字符串存储在php serialize()中。所以你可以做这样的事情

        $qb = $this->createQueryBuilder('d');
        $qb
            ->where(
                $qb->expr()->like('d.blocked_countries', "'%$country%'")
            )
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult()
        ;
© www.soinside.com 2019 - 2024. All rights reserved.