4

I am using Yii to deal with a mysql stored procedure. The sp takes several parameter, one of which is a output parameter.

After execute the sp, when I try to get the output parameter, I run into a error

CDbCommand failed to execute the SQL statement: 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 @error_info as result;

My mock up code is like:

$sql = 'CALL p_bid(:username, @param)';
$command = Yii::app()->db->createCommand($sql);
$command->bindParam(":username", $username, PDO::PARAM_STR);

$command->execute();

// the following line raise the error
$errorInfo = Yii::app()->db->createCommand("select @error_info as result;")->queryScalar();  

How can I walk around the question? Thanks.

7
  • The mock up code has a typing error, param should be error_info' Commented May 11, 2013 at 7:16
  • Just click on "edit" to edit your post. :) Commented May 11, 2013 at 7:23
  • Might be worth checking out: stackoverflow.com/questions/9017861/… According to that post its a PHP error, and was fixed by updating to PHP 5.3.2. Commented May 11, 2013 at 7:25
  • Thanks for your clue, I will try your suggestion and come back later. Commented May 11, 2013 at 7:37
  • 2
    I have figured it out, it is my mistake not to use it correctly. I should add the following lines. $command->getPdoStatement()->fetchAll(); 261 $command->getPdoStatement()->closeCursor(); Commented May 11, 2013 at 14:08

1 Answer 1

2

Try this, It's working for me

$command = $connection->createCommand("CALL r emove_places(:user_id,:placeID,:place_type,@out)"); 
$command->bindParam(":user_id",$user_id,PDO::PARAM_INT);
$command->bindParam(":placeID",$placeID,PDO::PARAM_INT);
$command->bindParam(":place_type",$place_type,PDO::PARAM_INT);
$command->execute();
$valueOut = $connection->createCommand("select @out as result;")->queryScalar(); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.