Best way to create this Query in Yii

Hello,

what is the best way to do this in Yii?

SET @i=0’

UPDATE stats SET old_rank = @i:=@i+1 ORDER BY column_x DESC, column_y DESC


$connection = yii::app()->db;

$sql = 'SET @i=0';

$command=$connection->createCommand($sql);

$command->execute();

$sql = 'UPDATE `stats` SET `old_rank` = @i:=@i+1 ORDER BY `column_x` DESC, `column_y` DESC';

$command=$connection->createCommand($sql);

$command->execute();

?

This should work,




$connection = yii::app()->db;

$sql = 'SET @i=0;';

$sql .= 'UPDATE `stats` SET `old_rank` = @i:=@i+1 ORDER BY `column_x` DESC, `column_y` DESC';

$command=$connection->createCommand($sql);

$command->execute();