Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Zend Framework 2中使用mysql用户变量_Php_Mysql_Variables_Zend Framework2 - Fatal编程技术网

Php 在Zend Framework 2中使用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

我想运行一个包含变量的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";

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

但结果值始终为1。如果直接运行查询,则有一行正确的数字。我想,变量将被取消设置,因此@counter在每一行上都是0。

我现在为此使用了一个存储过程。

检查这个:否,因为它已经是一个查询了。我想我应该用另一种方法。