I want to get some result from the mysql stored procedure in the OUT parameters, but for the case when the stored procedure also returns a result set via the select statement, as shown below.
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 ;
Work in the console below the specified command in order
call sp(5,@a) select @a
we get the result 5 => 5 @a => 664656
However, when I try to run the same code from php that got the error below
[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;.
Below you will find my php code.
$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;
Any ideas how to fix ???
PHP version 5.3.1
Yii version 1.1.9
Mysql Version 5.1.41-3ubuntu12.10
source share