0

I'm trying to call MySQL stored procedure from Laravel project. My stored procedure has two IN and two Out params. This is my call:

$procedure = DB::statement('CALL Table.Calculate("'.$Id.'", "'.$orderId.'",  @name,  @payout)');

When I var_dump procedure, I get bool(true).

This is my sotred procedure

 PROCEDURE table.Calculate(IN advid int, In cid INT,  OUT intTotalPayment INT, OUT TotalRevenue INT)
BEGIN
  SELECT SUM(Amount) INTO intTotalPayment
        FROM table.Transactions
        WHERE ID = advid;

  SELECT SUM(Payout) INTO TotalRevenue
        FROM table.Orders
        WHERE orderId= cid;

END

But I can't get @name and @payout.

Maybe anybody knows why? Thanks

Lusine Martirosyan
  • 79
  • 1
  • 5
  • 14
  • Show your Stored Procedure – Nazmul Hasan Jun 20 '17 at 07:53
  • You can call stored procedures like this in laravel 5 as described in this url [How to run mysql stored procedure call from a laravel GUI?](https://laravelportal.wordpress.com/2016/08/04/how-to-run-mysql-stored-procedure-call-from-a-laravel-gui/) – Kaviranga Oct 07 '17 at 09:30

1 Answers1

0

Use select instead of statement

$procedure = DB::select('CALL Table.Calculate("'.$Id.'", "'.$orderId.'",       

@name,  @payout)');

Replace your sp by the following

 PROCEDURE table.Calculate(IN advid int, In cid INT,  OUT intTotalPayment INT, OUT TotalRevenue INT)
BEGIN
  SELECT SUM(Amount) INTO intTotalPayment
        FROM table.Transactions
        WHERE ID = advid;

  SELECT SUM(Payout) INTO TotalRevenue
        FROM table.Orders
        WHERE orderId= cid;
  SELECT intTotalPayment,TotalRevenue;

END
Nazmul Hasan
  • 1,937
  • 13
  • 21
  • @ANazmul Hasan Maybe you can help me. Look at this : https://stackoverflow.com/questions/51838922/how-can-i-convert-many-statement-mysql-to-laravel-eloquent – moses toh Aug 15 '18 at 07:59