0

Here's the line that's making my query fail.

$query = $query->where('a.field LIKE :keyword OR LEFT(a.otherfield, 3) = LEFT(:keyword, 3)');

I get this error:

[Syntax Error] line 0, col 104: Error: Expected known function, got 'LEFT'

This SQL code works:

SELECT * FROM `table`
WHERE field LIKE 'searchterm'
OR LEFT(`otherfield`, 3) = LEFT('searchterm', 3)

Why does LEFT() return an error? Is there a different way to do it with query builder?

2
  • You will have to implement your own DQL function, please see this Commented Apr 12, 2016 at 20:05
  • 1
    Possible duplicate of Doctrine LEFT mysql function Commented Apr 12, 2016 at 21:20

2 Answers 2

1

Try to look at this question. Otherwise, try the old school way! native-sql-with-doctrine.

Sign up to request clarification or add additional context in comments.

Comments

0

@Houssem Zitoun's answer was good, and I'm marking it as the answer because it's relevant to my question. It's not the answer I used however

I already had the query written in sql that I wanted to use, so i decided to use a custom query with doctrine. It explains here how to do it. Symfony2 & Doctrine: Create custom SQL-Query

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.