1

我对 Symfony 很陌生,我想知道如何继续将列与字符串进行比较。

我在存储库中使用 QueryBuilder。MySQL 中等效的 WHERE 子句是:

WHERE UPPER(a.name) = UPPER(my_app_var)
class ApplicationRepository extends EntityRepository
{
    public function existsByName($name, $caseSensitive = false)
    {
        $builder = $this->createQueryBuilder('a');

        if ($caseSensitive)
        {
            $builder->where($builder->expr()->eq('a.name', $name));
        }
        else
        { 
            $builder->where($builder->expr()->eq('a.name', $builder->expr()->upper($name)));
        }

        return count($builder->getQuery()->getResult()) != 0; 
    }
}

Symfony 返回一个语法错误:

查询异常:SELECT a FROM Application a WHERE a.name = UPPER(my_var_app)

4

1 回答 1

1

您需要将最终变量包含在 '' (单引号)中以进行上调用。您还需要 "" (双引号)进行变量插值

   $builder->where($builder->expr()
                   ->eq('a.name'
                        ,$builder->expr()
                         ->upper("'$name'")));   //// here
于 2013-03-20T16:16:35.923 回答