sql server - How to get output values from a MS SQL stored procedure using PHP? -


i have following stored procedure on ms sql server:

create procedure checkfollowing  (     @mymemberid int,     @othermemberid int ) begin  if exists (select 1 followers follower = @mymemberid , followed = @othermemberid)     return 1 else     return 0     end  go 

in php code have method far:

function iamfollowing($mymemberid, $othermemberid) {     $query = "exec checkfollowing @mymemberid = ?, @othermemberid = ?";     $stmt = sqlsrv_query($this->con, $query, array(&$mymemberid, &$othermemberid));     $result = sqlsrv_fetch_array($stmt);      return $result[0]; } 

as have realised now, can't return values sqlsrv_fetch_array() command. canøt seem figure out how fetch outpur value using php. know how achieve this?

any gratly appreciated.

solution

create procedure checkfollowing  (     @mymemberid int,     @othermemberid int ) begin  if exists (select 1 followers follower = @mymemberid , followed = @othermemberid)     select 1 'output' else     select 0 'output'     end  go 

and php code should same. change return value to: $result['output'];

declare output parameter in sp's parameter list. output parameter return data calling application. check link more info

create procedure checkfollowing  (     @mymemberid int,     @othermemberid int,     @output int output ) begin  if exists (select 1 followers follower = @mymemberid , followed = @othermemberid)     select @output= 1 else     select @output= 0     end  go 

update:

to call sp , store output. try this

declare @appout int; -- variable hold data returned sp.  exec checkfollowing 10,20, @output = @appout output; -- how call sp.  @appout - hold data returned procedure. 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -