yii mssql storage procedure return value

Hi,guy

$command = Yii::app()->db->createCommand(“EXEC S_CreateAccount ‘$username’, ‘$password’, $adult”);

$result = $command->execute();

I want to get the return value of the mssql storage procedure. But just get number of rows affected by the execution.

How to get the return value? Can you help me? Thanks a lot.

Note:


ALTER        Procedure [dbo].[S_CreateAccount]

        @UserID             varchar(12),

        @UserPwd            varchar(32),

        @AdultSign			smallint = 2			--0:未成年人   1:成年人      2:没有身份证帐号

AS

BEGIN

SET NOCOUNT ON

  

	return 1   -- I want to get the value

END


SET 	NOCOUNT 	OFF



Hi!I have this same problem. My stored functions in Yii return number of rows affected by the execution, but in database is good.

This is my storage function:





CREATE FUNCTION is_login (login_in VARCHAR(20), password_in VARCHAR(255))

	RETURNS INT 

	DETERMINISTIC

	    BEGIN

	      DECLARE id_out INT;

	      DECLARE var VARCHAR(255);

	      DECLARE salt_var VARCHAR(4); 


	      SET @id_out = 0;

	      

		 SELECT salt INTO salt_var FROM user WHERE login LIKE login_in;

	      

	      SELECT SHA1(MD5(CONCAT(password_in,salt_var))) INTO var;

	      

	      SELECT id INTO @id_out FROM user WHERE login LIKE login_in AND password LIKE var;


	      RETURN IFNULL(@id_out, 0);

	      RETURN @id_out;

	      

	       

	    END




And this is how i call this storage function in yii:




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

		$command= $connection->createCommand('SELECT is_login("demo","user")');

		$ids = $command->execute();



Tell me please, what i doing bad ? :confused:

Ok, Ok i have answer for my questions:




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

$command= $connection->createCommand('SELECT is_login("user","user")');

$ids = $command->queryScalar();




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

                $command= $connection->createCommand('DECLARE @result INT; EXEC @result = is_login("demo","user"); select @result;');

                $ids = $command->queryScalar();

try this.

Yest, thx.

But i have questions, do you show me how I can value from stored procedure or stored function ?

just print the query result. You’ll get the answer. ;)

var_dump($ids); or print_r($ids);

Yes i know, i was tired and lost difference beetwen stored procedure na stored function.