How would I write a query such as:
SELECT id FROM Records WHERE name = BINARY 'My Record';
Using Doctrine Query Builder? 'My Record' could be any arbitrary name to query for.
The following does not work... Honestly, I didn't expect this to work but I can't think of anything else to try.
// Assume $repo is the Records repository
// Assume $name is the name to query, such as "My Record"
$repo->createQueryBuilder('r')
->select('r.id')
->where('r.name = BINARY :name')
->setParameter('name', $name)
->getQuery()
->getResult();
In order to support any DQL function not provided by the Doctrine ORM a custom user function would need to be used.
Install the DoctrineExtensions library as suggested by the Doctrine documentation.
Enable the
BINARYtype extension in the Symfony doctrine configuration.Now your DQL statements should support
r.name = BINARY(:name)Full list of provided DQL type extensions for MySQL.