I want to update the \"rank\" for a group of MySQL records with sequential numbers using a user-defined variable. The following query runs fine via the MySQL command line:
It is not possible to execute multiple statements in one query. Laravel uses PDO under the hood which prevents this. You could attempt to call this over 2 queries instead, since @rank
should be available for the duration of the connection.
DB::query("SET @rank:=0");
DB::query("UPDATE scores SET rank=@rank:=@rank+1 WHERE game_id=? ORDER BY score DESC", array(4));