Stored Procedure OUTPUT param VS RETURN VS SELECT

  • Hi All,

    I have been trying to get a Store Procedure to return a value for success or failure back to a PHP web application that's calling it.

    But i'm having absolutely no joy as PHP is not getting anything back, output param works fine in SQL though.

    So I have decided to use a Select instead. Are there any pitafalls in using a Select for returning something over an output parameter?

    Many Thanks

    B

  • this would not hurt only if this store procedure is executed independently. if you are using this store procedure in side a store procedure then it could hurt u.

    its a very regular thing to have an output parameter calling in a PHP. i would suggest u should do some Google on this related issue. i might not be the 1st one to have this issue. πŸ™‚

  • twin.devil (12/31/2013)


    this would not hurt only if this store procedure is executed independently. if you are using this store procedure in side a store procedure then it could hurt u.

    its a very regular thing to have an output parameter calling in a PHP. i would suggest u should do some Google on this related issue. i might not be the 1st one to have this issue. πŸ™‚

    I did get the output parameter working using the mssql library but it does not work on Linux server where you have to use dblib for PDO, PHP -> MSQL connections. That is why I had to resort to using the select.

  • you just need to make sure that this procedure is not in use in any other procedure beside that no harm using this approach.

  • The return value of a stored procedure is traditionally used for this:

    RETURN 0 if the procedure ran successfully

    RETURN -n if the procedure failed.

    ALTER PROCEDURE TestOutput @Outcome CHAR (4)

    AS IF UPPER(@Outcome) = 'FAIL' RETURN -1

    RETURN 0

    GO

    DECLARE @Returnvalue INT

    EXEC @Returnvalue = TestOutput 'PASS'

    PRINT @Returnvalue

    --prints 0

    EXEC @Returnvalue = TestOutput 'FAIL'

    PRINT @Returnvalue

    --prints -1

    β€œWrite the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply