"The active result contains no fields" using PDO with MS SQL
If you are using a stored procedure then use
SET NOCOUNT ON
The problem is that the stored procedure returns a result containing the number of rows affected as the first result.
Microsoft Documentation
If you are using a StoredProcedure
and doing something as:
DB::select("EXEC [storedprocedure] $param1,$param2;");
As per above, the PDO
expects the DB::select
statement to return some data. But as your StoredProcedure
does not return any data, you can change DB::select
TO DB::update
as belows:
DB::update("EXEC [storedprocedure] $param1,$param2;");
After this the error should no longer appear.
The PDO engine sees this query as returning two result sets (the older mssql engine probably just ignored all but the last query in an overall query string). I have managed to make it work by skipping over the first result set (the temporary table) using the following command
$statement->nextRowset();
And then using $statement->fetch();
as normal