Php 在Zend Framework 2中使用mysql用户变量
我想运行一个包含变量的mysql查询。简单的版本如下所示:Php 在Zend Framework 2中使用mysql用户变量,php,mysql,variables,zend-framework2,Php,Mysql,Variables,Zend Framework2,我想运行一个包含变量的mysql查询。简单的版本如下所示: $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"; $th
$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);
但结果值始终为1。如果直接运行查询,则有一行正确的数字。我想,变量将被取消设置,因此@counter在每一行上都是0。我现在为此使用了一个存储过程。检查这个:否,因为它已经是一个查询了。我想我应该用另一种方法。