0

I have a stored procedure that client has made. Now I have to access it and process data in my laravel app.

I have no problems with connecting to SQL but the problems starts when passing in parameters.

Here is my code:

$connections = DB::connection('sqlsrv')
    ->select(EXEC [stored].[procedure].[here] $param1, $param2);

The error I got back is: The active result for the query contains no fields

I have searched for many hours in forums and here is what I have found:

$connections = DB::connection('sqlsrv')
->select(DB::raw('EXEC [stored].[procedure].[here] $param1, $param2'));

Error I got back is: The active result for the query contains no fields.

I have installed SQL driver and OBDC driver.

Any help would be much appreciated

Bhavin Solanki
  • 1,364
  • 11
  • 27
Davis
  • 361
  • 1
  • 5
  • 19

2 Answers2

0

Don't know if this will help but this answer suggests you put your DB::raw around just the params instead of the EXEC stored.proc.name.

So instead of

 $connections = DB::connection('sqlsrv')->select(DB::raw('EXEC [stored].[procedure].[here] $param1, $param2'));

Try

 $connections = DB::connection('sqlsrv')->select('EXEC stored.proc.name' . DB::raw($param1, $param2));
ourmandave
  • 1,505
  • 2
  • 15
  • 49
  • Thanks for the help but if I do as you suggest then I got back the same message:active result for the query contains no fields – Davis Sep 10 '18 at 12:49
0

OK. So I found out the issue.

It turns out the client sent me over a variable with xml. As far as I figured out from Microsoft docs then you cant pass xml as a varable because if you call the SP from an application it is gonna pass it as an array and application cant parse xml into array directly. You have to do it on your own.

What can be done instead is to pass xml as a value of an array and then take it from there.

Davis
  • 361
  • 1
  • 5
  • 19