mercredi 19 juillet 2017

Using stored procedure in php Laravel 5.4

I'm quite a newbee at Laravel, using 5.4 I have a problem with using stored procedures.

The stored procedure should give the first 25 records of the relations with some details from other tables. It also checks the users rights. The result should be passed to the view.

I have this code in the controller:

public function index()
{
//        $relations=\DB::table('institutes')->get();
     $relations=\DB::select('call STP_Institutes (?, ?, ?, ?)',
        array (
            'p1' => "me@mail.com",
            'p2' => "blablabla",
            'p3' => 1,    //pagenumber
            'p4' => 25    /page size
            )
      )->get();

    return view('management.relationsAll.index')->with('relations',$relations);
}

In mySQL the procedure runs as expected, but Laravel gives a error:

(2/2) QueryException

SQLSTATE[HY000]: General error: 2031 (SQL: call STP_Institutes (me@mail.com, blablabla, 1, 25))

Calling a table directly (commend line) works like a charm. Leaving out the ->get does not give a error, but no results either. Already tried DB::raw(...)->get() and DB::select(DB::raw(..))->get(), but these gave errors to. Tried to find the answer for a couple of days, but non of the solutions I found seems to work. Laravels documentation on using stored procedures is very limited.

So how can I get the results from the stored procedure, insstead of the table?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2u9oMEp
via IFTTT

Aucun commentaire:

Enregistrer un commentaire