Saturday, March 11, 2017

Get Result of Stored Procedure Laravel

I am using Laravel 5.4 and MySql 5.7, PHP 5.6. I am trying to call a stored procedure (that does a SELECT query, joining multiple tables), and to get the result returned to my PHP.

Here are the things I've unsuccessfully tried:

PHP 1:

$result =  DB::select('CALL rentalsAvailables_get(?, ?, ?, ?)',
                array(
                    'p0' => Carbon::now(),
                    'p1' => Carbon::now()->addDays(7),
                    'p2' => 100,
                    'p3' => 2
                )
    );
return var_dump($result);

Result 1:

{
   "error": {
        "message": "SQLSTATE[HY000]: General error: 2031  (SQL: CALL rentalsAvailables_get(2017-03-11 16:00:42, 2017-03-18 16:00:42, 100, 2))",
        "code": "HY000",
        "status_code": 500
   }
}

PHP 2:

$result =  DB::select('CALL rentalsAvailables_get(:p0, :p1, :p2, :p3)',
                array(
                    'p0' => Carbon::now(),
                    'p1' => Carbon::now()->addDays(7),
                    'p2' => 100,
                    'p3' => 2
                )
    );
return var_dump($result);

Result 2:

array(0) {
}

Note:

I have of course checked and i am getting results from my query when calling it like that:

SET @p0='2017-03-11 04:26:09.000000';
SET @p1='2017-03-17 04:26:09.000000';
SET @p2='1000';
SET @p3='2';
CALL `rentalsAvailables_get`(@p0, @p1, @p2, @p3);

Did anyone already got this issue? Thanks for reading



via Thibaud Lacan

Advertisement