There is an interesting nuance when executing Transact-SQL stored procedures from PHP that I’ve run into. It seems that if your stored procedure has multiple Transact-SQL statements, PHP will only execute the first statement. This doesn’t mean that you can’t return multiple result sets, they just need to be in one Transact-SQL block or have one block and other queries that do use any variables ran normally prior or after the Transact-SQL block.
SET @SQL1 = 'Select * FROM Table1' SELECT @SQL1 EXEC sp_executesql @SQL1 SET @SQL2 = 'Select * FROM Table2' SELECT @SQL2 EXEC sp_executesql @SQL2 Select * FROM Table3
SET @SQL1 = 'Select * FROM Table1 Select * FROM Table2' SELECT @SQL1 EXEC sp_executesql @SQL1 Select * FROM Table3
I haven’t done extensive research on the cause, but I think it relates to how the PHP mssql_execute function handles SQL returns. I maybe completely off though.