How to use custom variables with MySQL?

I have a sql query adapted from Rank function in MySQL and I want to use it with Doctrine.
It seems that the system does not like my request, and I do not know where to start fixing it.

This query works fine in MySQL itself when I use it with Doctrine. I get a syntax error.

SELECT    l.*,
          @points:=l.playerPoints + l.organisationPoints,
          @curRank := if(@points <> @lastPoints, @curRank + 1, @curRank) AS rank,
          @lastPoints:= @points as points
FROM      leaderboard l, (SELECT @curRank := 0) r, (SELECT @lastPoints := 0) lp, (SELECT @points := 0) p
ORDER BY  l.playerPoints + l.organisationPoints DESC;

[Syntax error] line 0, col 10: Error: expected identity Variable | Scalar expression | Aggregate Expression | FunctionDeclaration | PartialObjectExpression | "(" Subselect ")" | CaseExpression, got a '@'

I am using the following PHP code:

$EntityManager->createQuery(...);

Doctrine 2?
, Doctrine 1 (MySQL User defined variable Doctrine Symfony).

+3
1

EntityManager:: createQuery DQL-, , Native SQL - , ( ).

+1

All Articles