I have a query that has a syntax error. This is the error!
string(63) “[Syntax Error] line 0, col 57: Error: Expected Literal, got ‘d'”
JavaScript
x
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();
}
}
Advertisement
Answer
Thanks, i made it like that because -> setParameter is safer
JavaScript
{
try {
return $this->createQueryBuilder('d')
->where('d.blocked_countries NOT LIKE :code')
->setParameter('code', "%$code%")
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
;
} catch (Exception $exception) {
return null;
}
}