【发布时间】: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
【问题讨论】:
-
谁能帮忙解决问题?