我使用Yii来处理mysql存储过程。sp接受几个参数,其中一个是输出参数。
在执行sp之后,当我试图获得输出参数时,我遇到了一个错误
CDbCommand failed to execute SQL statement: SQLSTATE[HY000]: General error: 2014当其他未缓冲的查询处于活动状态时,不能执行查询。考虑使用PDOStatement::fetchAll()。或者,如果你的代码只对mysql运行,你可以通过设置PDO::MYSQL_ATTR_USE_BUFFERED_QUERY属性来启用查询缓冲。执行的SQL语句是:select @error_info as result;
我的模拟代码是这样的:$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();
我如何绕过这个问题?谢谢。
试试这个,它对我有用
$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();