0

I want to run a mysql query including variables. A simple version of this looks like that:

$sql = "UPDATE mytable,
(SELECT @counter := IFNULL(@counter,0) + 1 as new_value,
        mycolumn
 FROM othertable
 ORDER BY mycolumn) i
SET mytable.counter_column = i.new_value
WHERE i.mycolumn = mytable.mycolumn";

$this
  ->getSlaveSql()
  ->getAdapter()
  ->getDriver()->getConnection()->execute($sql);

But the result value is always 1. If I run the query directly, I have a correct line of numbers. I think, the variables will be unset bei Zend, so that @counter is 0 on every row.

edigu
  • 9,878
  • 5
  • 57
  • 80

1 Answers1

0

I used a stored procedure for this now.