Update with query object to re-number table rows


Hi! can anybody help?

I try to renumber rows in a table. Directly with SQL i would use this expression:

SET @x=0; UPDATE tasks SET lfdnum=(SELECT @x:=@x+2) ORDER BY lfdnum

How would this look like when using cakephp query->update… ?

Thanx for your help!


Something like that:

$this->Tasks->connection()->execute('SET @x=0');
$this->Tasks->query()->update()->set(['lfdnum' => new QueryExpression('SELECT @x:=@x+2')])->order('lfdnum')->execute();