Im trying to select from a table where the selected duration divided by the entry duration equals has no remainder.
$qb = $em->createQueryBuilder()
->from('AcmeBlogBundle:Entry', 'e')
->andWhere(":duration % e.duration = 0")
->setParameter('duration', $duration);
This returns the error:
[Syntax Error] line 0, col 226: Error: Expected =, <, <=, <>, >, >=, !=, got '%'
This would work in plain SQL. Does anybody know how to do this with Doctrine's query builder?
The ORM's query builder provides a simple to use fluent interface for creating and running queries.
Using Query Builder, you can search and filter database objects, select objects and columns, create relationships between objects, view formatted query results, and save queries with little or no SQL knowledge.
SQL query builder, written in c#, helps you build complex queries easily, supports SqlServer, MySql, PostgreSql, Oracle, Sqlite and Firebird. sqlkata.com.
Doctrine features a powerful query builder for the SQL language. This QueryBuilder object has methods to add parts to an SQL statement. If you built the complete state you can execute it using the connection it was generated from. The API is roughly the same as that of the DQL Query Builder.
The symbol %
is not a DQL operator. Try this:
$qb = $em->createQueryBuilder()
->from('AcmeBlogBundle:Entry', 'e')
->andWhere("mod(:duration,e.duration) = 0")
->setParameter('duration', $duration);
Or read this: http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/dql-doctrine-query-language.html The 12.5.1 paragraph.
MOD(a, b) - Return a MOD b.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With