How to execute Stored Procedure from Laravel

前端 未结 11 1596
无人及你
无人及你 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:56

    Running the Microsoft SQL Server Stored Procedure (MS SQL Server) using PHP Laravel framework. If you are trying to run SP using Laravel Model then you can use following two approaches.

    $submit = DB::select(" EXEC ReturnIdExample ?,?", array( $paramOne ,$paramTwo ) ); 
    
    $submit = DB::select(" EXEC ReturnIdExample $paramOne,$paramTwo ");
    

    If incase you are passing the Varchar Parameter then use the following:

    $submit = DB::select(" EXEC ReturnIdExample '$paramOne', '$paramTwo' ");
    

    If you are just passing parameter which are of INT or BIGINT then this should work and you can get the return from SP:

    $submit = DB::select(" EXEC ReturnIdExample $paramOne,$paramTwo ");
    

    Once the stored procedure is executed the values will be present in the $submit in the form of array, you need to loop through it and access the required columns.

    foreach($submit  as $row)
    {
    
    echo $row->COLUMN1;
    echo $row->COLUMN2;
    echo $row->COLUMN3;
    
    }
    

提交回复
热议问题