1

Stored procs in SQL Server sometimes finish with a return code, as opposed to a recordset of data. I've seen ASP code that's able to get this return code, but I can't figure out how to get this code with PHP's mssql driver.

mssql_get_last_message() always returns nothing, and I'm thinking it's because it only returns the very last line that came from the server. When we run the proc in another application (outside PHP), there is blank line following the return code.

Has anyone figured out how to get return codes from SQL stored procs using PHP's mssql driver?

2 Answers 2

2

Are you talking about SQL Server error codes, e.g. RAISERRROR or other failures? If so, last time I checked in PHP you need to ask for @@ERROR (e.g. select @@error) instead.

If it is a return code, you must explicitly catch it, e.g.

DECLARE @return_code INT
EXEC @return_code = your_stored_procedure 1123
SELECT @return_code
Sign up to request clarification or add additional context in comments.

Comments

0

To get a numeric error code from mssql you can do a select that looks something like

SELECT @@ERROR AS ErrorCode

Which SHOULD return the correct error code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.