Stored Procedure Out Parameter

Dear All,

Could some one advise me how to deal with OUT parameters in Yii?

$connection = Yii::app()->db;

$command = $connection->createCommand("CALL remove_cars($user_id,$car_id,$car_type,$outParm)"); 


$outParm is the one that I want to get back from stored procedure .

The approach I tried is not working .

Thanks for your help


Yii Fan

read binding parameters

$sql="INSERT INTO tbl_user (username, email) VALUES(:username,:email)";


// replace the placeholder ":username" with the actual username value


// replace the placeholder ":email" with the actual email value



// insert another row with a new set of parameters




binding with bindParam function is bidirectional (by reference), so you should get return value in one of such defined params. If you want to bind only value (by value) - use bindValue function instead.

Thank You redguy .

Unfortunately that approach is not working .

But found a way and here it is

        $command = $connection->createCommand("CALL remove_places(:user_id,:placeID,:place_type,@out)"); 





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


Yii Fan

according to PDO this could also work:


$command->bindParam(':out', $valueOut, PDO::PARAM_STR|PDO::PARAM_INPUT_OUTPUT, '');


have you tried to define param as INPUT_OUPUT?

Thank You again . I tried this approach but this also didn’t help . May be I am doing some thing . As you said It should work . I tried even changing SP parameter to INOUT but still no luck . I will see if I can get any exceptions for this and try to debug it .

Thanks again

Hey there,

I hope this may help you…

$db = Yii::$app->db;

$command = $db->createCommand('CALL DATABASE_NAME.PKG_NAME.PROCEDURE_NAME(:code,@out_rv)');

$command->bindParam(":code_o", $code_o, PDO::PARAM_STR);


$RV = $db->createCommand("select @out_rv as rv;")->queryScalar();

Happy Coding…