How to execute Stored Procedure from Laravel

前端 未结 11 1554
无人及你
无人及你 2020-12-01 00:28

I need to execute a stored procedure after my form submits data. I have the stored procedure working like I want it, and I have my form working properly. I just do not know

相关标签:
11条回答
  • 2020-12-01 00:36
    app('db')->getPdo()->exec('exec my_stored_procedure');
    
    0 讨论(0)
  • 2020-12-01 00:39

    for Laravel 5.4


    DB::select(DB::raw("exec my_stored_procedure"));
    

    if you want to pass parameters:

    DB::select(DB::raw("exec my_stored_procedure :Param1, :Param2"),[
        ':Param1' => $param_1,
        ':Param2' => $param_2,
    ]);
    
    0 讨论(0)
  • 2020-12-01 00:42

    After a long research, this works:

    DB::connection("sqlsrv")->statement('exec Pro_Internal_Transfer_Note_post @mvoucherid='.$VMID);
    
    0 讨论(0)
  • 2020-12-01 00:48

    MySql with Laravel 5.6(or above version may be)

    DB::select( 'call sp($id)' );

    0 讨论(0)
  • 2020-12-01 00:49

    For version 5.5 use CALL:

    return DB::select(DB::raw('call store_procedure_function(?)', [$parameter]))
    
    0 讨论(0)
  • 2020-12-01 00:52

    Try something like this

    DB::select('exec my_stored_procedure("Param1", "param2",..)');
    

    or

    DB::select('exec my_stored_procedure(?,?,..)',array($Param1,$param2));
    

    Try this for without parameters

    DB::select('EXEC my_stored_procedure')
    
    0 讨论(0)
提交回复
热议问题