我目前正试图根据他们的胜负数量来获得玩家的等级。我正在使用以下sql:
"SELECT rank FROM(SELECT playerid,@r:=@r + 1 rank FROM leaderboard
ORDER BY leaderboard.wins desc, leaderboard.loses asc) t1,
(SELECT @r:=0) t2
WHERE playerid=$userId"
在mysql中执行时,结果似乎有效。
但是,当我尝试在Symfony 2下的Doctrine中运行它时。列等级的值始终为null。
$em = $this->em;
$connection = $em->getConnection();
$statement = $connection->prepare("SELECT rank FROM
(SELECT playerid,@r:=@r + 1 rank FROM leaderboard
ORDER BY leaderboard.wins desc, leaderboard.loses asc
) t1,(SELECT @r:=0) t2
WHERE playerid=$userId");
$statement->execute();
$results = $statement->fetchAll();
$ result的var_dump会打印以下内容:
array (size=1)
0 =>
array (size=1)
'rank' => null
在MySql Workbench中复制粘贴$ statement-> getWrappedStatement()的值会返回正确的值。
这是因为变量@r?