DDC-3472: Use REGEXP or RLIKE #4280

Closed
opened 2026-01-22 14:38:42 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Dec 31, 2014).

Originally assigned to: @Ocramius on GitHub.

Jira issue originally created by user sweetguy0883:

How can I use the REGEXP or RLIKE commands with Doctrine ORM? In most of the place over internet it says that this is not possible but all the posts are more than 1 year old. I found some function named getRegexpExpression() in https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php but don't know how to use it.

I am currently upgrading my old project and using php, doctrine and twig (not using any framework like Symfony2). I want to make a local php search (I don't want to use ElasticSearch or Solr as I am on a shared hosting). Lately I used some sql like "SELECT id FROM topics WHERE topic REGEXP ':<:something:>:'" . I am mainly searching for an alternative to my query for proper result.

$query = $entityManager->createNativeQuery("SELECT id FROM topics WHERE topic RLIKE ':<:something:>:'", $rsm); and it gives a null return value.

If there is any better option for making a search, that will also help me

Originally created by @doctrinebot on GitHub (Dec 31, 2014). Originally assigned to: @Ocramius on GitHub. Jira issue originally created by user sweetguy0883: How can I use the REGEXP or RLIKE commands with Doctrine ORM? In most of the place over internet it says that this is not possible but all the posts are more than 1 year old. I found some function named getRegexpExpression() in https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php but don't know how to use it. I am currently upgrading my old project and using php, doctrine and twig (not using any framework like Symfony2). I want to make a local php search (I don't want to use ElasticSearch or Solr as I am on a shared hosting). Lately I used some sql like "SELECT id FROM topics WHERE topic REGEXP '[[:<:]]something[[:>:]]'" . I am mainly searching for an alternative to my query for proper result. $query = $entityManager->createNativeQuery("SELECT id FROM topics WHERE topic RLIKE '[[:<:]]something[[:>:]]'", $rsm); and it gives a null return value. If there is any better option for making a search, that will also help me
admin closed this issue 2026-01-22 14:38:42 +01:00
Author
Owner

@doctrinebot commented on GitHub (Dec 31, 2014):

Comment created by @ocramius:

Seems like getRegexpExpression is not being used at all by the ORM. I suggest you to look at how to write custom DQL functions as described in http://www.doctrine-project.org/2010/03/29/doctrine2-custom-dql-udfs.html

Note that public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) can actually access the DB connection and then the platform via Doctrine\ORM\Query\SqlWalker#getConnection().

There is also a MySql specific implementation at 5e4ec9c3ec/lib/DoctrineExtensions/Query/Mysql/Regexp.php

This won't be implemented in core so far, closing.

@doctrinebot commented on GitHub (Dec 31, 2014): Comment created by @ocramius: Seems like `getRegexpExpression` is not being used at all by the ORM. I suggest you to look at how to write custom DQL functions as described in http://www.doctrine-project.org/2010/03/29/doctrine2-custom-dql-udfs.html Note that `public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)` can actually access the DB connection and then the platform via `Doctrine\ORM\Query\SqlWalker#getConnection()`. There is also a MySql specific implementation at https://github.com/beberlei/DoctrineExtensions/blob/5e4ec9c3ec3434151e1c73144b4ab87ae30aefbc/lib/DoctrineExtensions/Query/Mysql/Regexp.php This won't be implemented in core so far, closing.
Author
Owner

@doctrinebot commented on GitHub (Dec 31, 2014):

Issue was closed with resolution "Won't Fix"

@doctrinebot commented on GitHub (Dec 31, 2014): Issue was closed with resolution "Won't Fix"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4280