Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot retrieve output parameters from SQL Server stored procedure using PHP
    primarykey
    data
    text
    <p>I am executing a SQL Server stored procedure that is supposed to return an output parameter (ErrCode), as well as a resultset.</p> <p>I am calling the procedure from PHP using the following code, but so far have been unable to retrieve the output parameter:</p> <pre><code>$stmt = mssql_init("addFaculty", $this-&gt;db); mssql_bind($stmt, "@FacultyID", $FacultyID, SQLCHAR); ...imagine other parameters here... mssql_bind($stmt, "@ErrCode", &amp;$ErrCode, SQLINT1, TRUE, FALSE, 1); $result = mssql_execute($stmt); echo $ErrCode </code></pre> <p>$ErrCode is always echoed as 0, even when it should return a '1' or '2'. When I execute the procedure within SQL Server Studio, however, the 'Messages' tab will correctly display a '1' or a '2'.</p> <p>In doing research, I found one suggestion that stated you must use <code>mssql_next_result()</code> first to be able to access the output parameters. I tried this, but it simply returned a PHP </p> <blockquote> <p>"Warning: mssql_next_result(): supplied argument is not a valid MS SQL_result resource"</p> </blockquote> <p>I also found a reference to a similar issue in <a href="https://stackoverflow.com/questions/480991/mssql-stored-procecure-output-params-in-php">this thread</a> but did not see a real resolution.</p> <p>Like the person in that thread, I am using Linux (CentOS) with PHP5 and MS SQL Server 2005.</p> <p>Does anyone have any suggestions on this? I had an issue like this in a previous project as well, and in the end, simply gave up on using output parameters (and did all my error_checking in the PHP instead) because I couldn't figure it out. It would be nice to find an answer :(</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload