0

I am executing a SQL Server 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 :(

Community
  • 1
  • 1
Kirsehn
  • 215
  • 4
  • 10

3 Answers3

0

Check my post on this problem, I used a class extended from Zend_Db_Table_Abstract. I do not use pure PHP, still using the framework accordingly. Seens to be fine and run ok, I am even getting also the resultset back! Hope it helps:

Execute MSSQL stored procedure via Zend Framework

Community
  • 1
  • 1
0

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
  • 21,295
  • 6
  • 46
  • 61
  • 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 Apr 15 '09 at 19:34
0

EDIT:

Have you tried ADODB

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383