【问题标题】:CDbCommand::fetchColumn() failed: SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are activeCDbCommand::fetchColumn() 失败:SQLSTATE [HY000]:一般错误:2014 在其他无缓冲查询处于活动状态时无法执行查询
【发布时间】:2012-01-26 12:04:24
【问题描述】:

我希望能够在 OUT 参数中从 mysql 存储过程中获得一些输出,但对于存储过程还通过如下所示的 select 语句返回结果集的情况。

DELIMITER $$

DROP PROCEDURE IF EXISTS `RD`.`sp`$$

CREATE DEFINER=`root`@`%` PROCEDURE `sp`(in b int, out a int)
BEGIN
select 664656 into a;

select 5;
END$$

DELIMITER ;

在控制台中运行下面提到的命令一一

call sp(5,@a)
select @a

我们会得到结果 5 => 5 @a => 664656

但是,当我尝试从 php 运行相同的代码时,出现以下错误

[error] [system.db.CDbCommand] CDbCommand::fetchColumn() failed: 
SQLSTATE[HY000]: General error: 2014 Cannot execute queries while other unbuffered queries are active.  
Consider using PDOStatement::fetchAll().  
Alternatively, if your code is only ever going to run against mysql,
 you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.. The SQL statement executed was: select @a as result;.

请在下面找到我的 php 代码。

$connection = Yii::app ()->db;
    $b=7;
    $command = $connection->createCommand ( "CALL sp(:b,@a)" );
    $command->bindParam ( ":b", $b, PDO::PARAM_INT );
    $command->execute();

    $command->getPdoStatement()->fetchAll();

    $command->getPdoStatement()->closeCursor();

    $valueOut = $connection->createCommand ( "select @a as result;" )->queryScalar ();


    echo $valueOut;

任何想法如何解决???

PHP 版本 5.3.1

Yii 1.1.9 版

Mysql 版本 5.1.41-3ubuntu12.10

【问题讨论】:

  • 谁能帮忙解决问题?

标签: php mysql pdo yii


【解决方案1】:

最后我发现了问题,它是 php 版本的。 https://bugs.php.net/bug.php?id=39858 我将版本更新到 PHP 版本 5.3.2,现在可以正常工作了。 请注意,它不能在相同版本的 windows 下工作,只能在 linux 下工作。(至少对我来说)。

【讨论】:

  • 我有 PHP 5.4.7,但我有一个简单的问题 -> 查询
  • 你是用windows还是linux?
猜你喜欢
  • 1970-01-01
  • 2017-02-20
  • 1970-01-01
  • 1970-01-01
  • 2015-12-24
  • 2019-12-23
  • 2013-06-30
相关资源
最近更新 更多