I am using Doctrine 2.1 and need to use a REGEXP in MySQL.
REGEXP is not currently supported in the default installation of Doctrine so I am using beberlei/DoctrineExtensions
I cannot get Doctrine to recognize my REGEXP, I have followed the example on SO.
I'm using Doctrine 2.1 and Symfony 2.7.1
Here's the code, any ideas?
Config
# config.yml
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
keep_slave: true
slaves: %database_slaves%
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
metadata_cache_driver: apc
query_cache_driver: apc
result_cache_driver:
type: service
id: cache
dql:
string_functions:
regexp: DoctrineExtensions\Query\Mysql\Regexp
Repository
// GroupRepository
$dql = "SELECT g FROM {$this->_entityName} g WHERE g.name REGEXP '^[:alpha:]'";
return $this->getEntityManager()->createQuery($dql)->getResult();
Error on page load
// Error
CRITICAL - Uncaught PHP Exception Doctrine\ORM\Query\QueryException: "[Syntax Error] line 0, col 64: Error: Expected =, <, <=, <>, >, >=, !=, got 'REGEXP'" at /symfony/vendor/doctrine/orm/lib/Doctrine/ORM/Query/QueryException.php line 52
UPDATE:
I've updated the query to match the expected format
$dql = "SELECT g FROM {$this->_entityName} g WHERE REGEXP(g.name, '^[:alpha:]')";
Now I have started getting a new error:
[Syntax Error] line 0, col -1: Error: Expected =, <, <=, <>, >, >=, !=, got end of string.