Wednesday, March 1, 2017

Laravel 5: call mysql procedure with while

I have this mysql procedure

DROP PROCEDURE IF EXISTS `kassa`;

DELIMITER //
CREATE PROCEDURE `kassa` (IN date_of_month INT)
BEGIN
SET @d = 1;
WHILE (@d < date_of_month) DO
SET @date_p = CONCAT('2017-02-', @d);   
SELECT @date_p, SUM(amount) as kassa_begin, account_id
    FROM payment_types as k_pt 
    JOIN payments as p ON p.id = k_pt.pid
    WHERE k_pt.created_at BETWEEN '1970-01-01 00:00:01' AND CONCAT(@date_p,     ' 00:00:01') and p.gbar_id = 1
GROUP BY account_id;
SET @d = @d + 1;
END WHILE;
END//
DELIMITER ;

If call kasss(28) for 28 days, it returned 28 results. Thsi is okey

But, i want call this procedure from Laravel 5

I try

$financial_report = DB::select('CALL kassa(28)');
dd($financial_report);

But it returner ONLY FIRST!!! result How i must execute this procedure for have all results?




via Taras Germanyuk From Ukraine

Advertisement