0

I have own mini php MVC, and need to add the beberlei/DoctrineExtensions. I am not able to figure out, how to add/configure and to use beberlei/DoctrineExtensions. Currently, i have this configuration :

require_once INC_ROOT . '/vendor/doctrine/common/lib/Doctrine/Common/ClassLoader.php';
use Doctrine\Common\ClassLoader;
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine');
$classLoader->register();

$classLoader2 = new \Doctrine\Common\ClassLoader('DoctrineExtensions', '/vendor/beberlei/DoctrineExtensions');
$classLoader2->register();

I want to select appIds similar to 20aliasApp871, starting with any digit followed by aliasApp string, and then the number higher then 870 ( but there are no more thane 1500).

    $appIds = $qb->select( 'a.id' )  
        ->from( 'BookBundle\Entity\App', 'a' )
        ->where ( ' REGEXP(a.aliasApp, .*aliasApp[189]{1}[0123456789]{2,3}) = true ')
        ->getQuery()
        ->getResult();

I am getting Fatal error:

    Fatal error: `Uncaught Doctrine\ORM\Query\QueryException: 
SELECT a.id FROM BookBundle\Entity\App a WHERE REGEXP(a.aliasApp, .*aliasApp[189]{1}[0123456789]{2,3}) = true` 
in vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php:41 Stack trace: 
#0 \vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(448): Doctrine\ORM\Query\QueryException::dqlError('SELECT a.id FRO...') 
#1 vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(3379): Doctrine\ORM\Query\Parser->syntaxError('known function', Array) 
#2 vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(3351): Doctrine\ORM\Query\Parser->CustomFunctionDeclaration()
#3 vendor\doctrine\orm\lib\Doctrine\ORM\Query\Parser.php(2810): Doctrine\ORM\Query\Parser->FunctionDeclaration() 
#4 vendor\doctrine\orm\lib\Doctrine\ORM\Query\QueryException.php on line 52
Darzen
  • 1,105
  • 3
  • 13
  • 29
olga
  • 959
  • 1
  • 15
  • 42
  • Is this page helpful? https://stackoverflow.com/questions/6574760/regex-with-doctrine-2-query-builder (I don't use Doctrine) – mickmackusa Nov 02 '17 at 22:54
  • I think your plugin is bad `REGEXP(a.aliasApp, .*aliasApp[189]{1}[0123456789]{2,3})` unless this isn't MySql, doesnt matter if its doctrine still has to be valid SQL, I don't use RegExp in mysql much though, so what do I know https://dev.mysql.com/doc/refman/5.7/en/regexp.html – ArtisticPhoenix Nov 02 '17 at 23:13
  • The first thing I would do, is open PHPmyAdmin, and try the query in it, then I would fix the query. Once I am satisfied with that I would fix/replace whatever code is generating it. – ArtisticPhoenix Nov 02 '17 at 23:17

1 Answers1

0
  • Don't use backslashes in table name.

  • REGEXP is an operator, not a function: WHERE a.aliasApp REGEXP '.*aliasApp[189]{1}[0123456789]{2,3}'

  • Complain to Doctrine for not providing as useful an error message as MySQL gave to it.

Rick James
  • 135,179
  • 13
  • 127
  • 222