预期已知功能,得到“MD5" [英] Expected known function, got 'MD5'

查看:18
本文介绍了预期已知功能,得到“MD5"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要进行这样的搜索:

I need to do a search like this:

//ProjectMyBundleRepository

$query = $this->getEntityManager()->getRepository('ProjectMyBundle:Product')->createQueryBuilder('p')
        ->where('MD5(p.id) = :id')
        ->setParameter('id', $id )
        ->getQuery()
        ->getSingleResult();

我得到了 MD5 上的 id,必须在数据库中搜索 MD5 上的 id.

I get the id on MD5 and have to search for an id on MD5 in the database.

当我进行搜索时,我出现了,给了我以下错误:

When I do a search, I showed up, gives me the following error:

[语法错误] 第 0 行,第 51 列:错误:预期已知函数,得到 'MD5'

[Syntax Error] line 0, col 51: Error: Expected known function, got 'MD5'

表示lib:

https://github.com/beberlei/DoctrineExtensions/blob/master/lib/DoctrineExtensions/Query/Mysql/Md5.php

但我已经把它放在文件夹里了,现在我需要知道它应该放在什么地方.

But I've put it inside the folder and now I need to know where it should matter.

我在 Symfony 2.1.6 中使用 MySQL,Doctrine 2.2.

I am using MySQL, Doctrine 2.2 in Symfony 2.1.6.

推荐答案

您需要将 MD5 注册为自定义 DQL 函数:

You'll need to register MD5 as a custom DQL function:

# app/config/config.yml
doctrine:
    orm:
        # ...
        entity_managers:
            default:
                # ...
                dql:
                    string_functions:
                        MD5: AcmeHelloBundleDQLMD5Function

有关更多信息,请参阅:http://symfony.com/doc/2.0/cookbook/doctrine/custom_dql_functions.html

For more info, see: http://symfony.com/doc/2.0/cookbook/doctrine/custom_dql_functions.html

这篇关于预期已知功能,得到“MD5"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆