views:

3000

answers:

3

I am executing a MSSQL stored procedure that is supposed to return an output parameter (ErrCode), as well as a resultset.

I am calling the procedure from PHP using the following code, but so far have been unable to retrieve the output parameter:

$stmt = mssql_init("addFaculty", $this->db);

mssql_bind($stmt, "@FacultyID", $FacultyID, SQLCHAR);
...imagine other parameters here...
mssql_bind($stmt, "@ErrCode", &$ErrCode, SQLINT1, TRUE, FALSE, 1);

$result = mssql_execute($stmt);

echo $ErrCode

$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'.

In doing research, I found one suggestion that stated you must use mssql_next_result() first to be able to access the output parameters. I tried this, but it simply returned a PHP "Warning: mssql_next_result(): supplied argument is not a valid MS SQL_result resource"

I also found a reference to a similar issue in this thread but did not see a real resolution.

Like the person in that thread, I am using Linux (CentOS) with PHP5 and MS SQL Server 2005.

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 :(

A: 

I am not a PHP guy, but I think this will help.

It says:

Note that when retrieving an output or input/output parameter, all results returned by the stored procedure must be consumed before the returned parameter value is accessible.

Kirtan
Hi Kirtan,Thanks for the link. Unfortunately this did not resolve my issue. It looks like for the link you provided they are using a windows server and using different drivers. Perhaps the fact I am on linux is part of the problem, but I feel like there must be a solution.
Kirsehn
A: 

EDIT:

Have you tried ADODB

Phill Pafford
This is Mssql...
Svetlozar Angelov
A: 

I am having the same problem, it's in the FreeTDS FAQ.

http://freetds.org/faq.html#ms.output.parameters

I am still trying to find a fix, going to try and get the patched version from earlier this year installed.

benembery