Doctrine Query Builder mysql Functions
Those AVG
and Count
are DQL aggregate functions, they have nothing to do with SQL. So there is no way to call UDF's from DQL, except for RawSQL
But, if you are using doctrine2, you might want to have a look at Adding your own functions to the DQL language and Extending DQL in Doctrine 2: User-Defined Functions.
i know this question is very old, but i am answering this question for others who having same error.
you just need to add below code in form of file Named "SecToTime.php" as below path.
YourProjectName\libraries\Doctrine\DoctrineExtensions\Query\MySql\SecToTime.php
And put below code in above file Named "SecToTime.php".
<?php
namespace DoctrineExtensions\Query\Mysql;
use Doctrine\ORM\Query\AST\Functions\FunctionNode,
Doctrine\ORM\Query\Lexer;
class SecToTime extends FunctionNode {
public $time;
/**
* @override
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) {
return 'SEC_TO_TIME(' . $sqlWalker->walkArithmeticPrimary($this->time) . ')';
}
/**
* @override
*/
public function parse(\Doctrine\ORM\Query\Parser $parser) {
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->time = $parser->ArithmeticPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
you need to add above file name in your doctrine.php file for using it further. i hope you know how to add it.
If you having any query, feel free to ask.