久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel 模型 SQL Server:從存儲過程中獲取輸出參數

Laravel Model SQL Server: Get Output Parameters from Stored Procedure(Laravel 模型 SQL Server:從存儲過程中獲取輸出參數)
本文介紹了Laravel 模型 SQL Server:從存儲過程中獲取輸出參數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想從我的 Laravel 模型中的 SQL Server 存儲過程獲取輸出參數,該存儲過程在 SQL Server 管理工具和 NORMAL php 文件中運行良好,但在 Laravel 模型中不起作用.

I want to get the output parameter from my SQL Server stored procedure in the Model of my Laravel, The Stored Procedure is working perfectly in the SQL Server Management tool and also in NORMAL php file but it does not work in LARAVEL MODEL.

這是我在 Laravel 模型中執行存儲過程的方式:

This is how I am executing the Stored Procedure in the Laravel Model:

    $id              =   "123454";
    $email           =   "ABC@ABC.com";
    $name            =   "FName, LName";
    $returnval        =   1; //My OUTPUT PARAMETER from SP
    $action       =   'ACTION_MESSAGE;
    $dummy            =   0;
    $client          =   $request->input('client');
    $team_l          =   $request->input('team');
    $contact         =   $request->input('contact');
    $team            =   $request->input('team_l');

    $Query        =  DB::select
                            (" SET NOCOUNT ON; SET ANSI_NULLS ON; SET ANSI_WARNINGS ON; EXEC [MY_STORED_PROC]
                                        $client,
                                        $team,
                                        $contact,
                                        '$team_l',
                                        '$id',
                                        '$name',
                                        '$email',
                                        '$action',
                                        $dummy,
                                        $returnval
                            ");

在 Laravel 中,當我嘗試運行存儲過程時出現以下錯誤:

In Laravel I am getting following error when I try to run the Stored Procedure:

(3/3) QueryException
SQLSTATE[IMSSP]: The active result for the query contains no fields.

這是我在正常運行的普通 PHP 中使用的方式:

This is how I was using in the Normal PHP which was working:

    $id              =   "123454";
    $email           =   "ABC@ABC.com";
    $name            =   "FName, LName";
    $returnval       =   1; //My OUTPUT PARAMETER from SP
    $action          =   'ACTION_MESSAGE;
    $dummy           =   0;
    $client          =   $_POST('client');
    $team            =   $_POST('team');
    $contact         =   $_POST('contact');
    $team_l          =   $_POST('team_l');

    $Query        = "{ CALL  My_PROC_NAME(?,?,?,?,?,?,?,?,?,?) }";
    $PARAMS           = array(   array($client, SQLSRV_PARAM_IN),
                                array($team,        SQLSRV_PARAM_IN),
                                array($contact, SQLSRV_PARAM_IN),
                                array($team_l,      SQLSRV_PARAM_IN),
                                array($id,         SQLSRV_PARAM_IN),
                                array($name,       SQLSRV_PARAM_IN),
                                array($email,       SQLSRV_PARAM_IN),
                                array($action,      SQLSRV_PARAM_IN),
                                array($dummy,       SQLSRV_PARAM_IN),
                                array($returnval,   SQLSRV_PARAM_OUT)
                            );              

        $result     =   sqlsrv_query($connect, $Query,$PARAMS);

我的存儲過程和一切似乎都很好.我也嘗試了將以下內容保留在存儲過程中,但沒有成功:

My Stored Procedure and everything seems to be fine. I tried the following things keeping in the stored procedure as well but no luck:

SET NOCOUNT ON; 
SET ANSI_NULLS ON; 
SET ANSI_WARNINGS ON;

我是否必須在 SP 中選擇返回參數,以便我們可以循環并在 LARAVEL MODEL 中獲取它.

Do I have to SELECT the return parameter in the SP so we can loop and get it in the LARAVEL MODEL.

推薦答案

非常感謝大家.

發布此答案,因為它對在 Web 開發過程中受到打擊的人很有用.

Posting this answer as it will be useful to someone who will get struck during their web development.

在做了大量的研究和嘗試了很多事情之后,我知道答案就在我的問題的底部,我建議在我的存儲過程的末尾添加 SELECT ,它將把值返回給我的 Laravel模型.

After doing lot of research and trying out numerous things I got to know the answer was lying at the bottom of my question itself where I had proposed to add SELECT at the end of my stored procedure which will return the value to my Laravel Model.

這是一個示例存儲過程:

Here is a sample Stored Procedure:

CREATE PROCEDURE ReturnIdExample
    (
             @paramOne int
            ,@paramTwo nvarchar(255)
    )
    AS

    SET NOCOUNT ON; --IMPORTANT!

    BEGIN

    -- Grab the id that was just created
    DECLARE @ObjectID int;

    INSERT INTO [Table]
    (
             [ColumnNameA]
            ,[ColumnNameB]
    ) VALUES (
             @paramOne
            ,@paramTwo
    )

    SET @ObjectID = SCOPE_IDENTITY();

    -- Select the id to return it back to laravel
    SELECT@ObjectID AS ObjectID;

END

在 Laravel 模型/控制器中調用這個存儲過程:

Calling this Stored Procedure in Laravel Model/Controller:

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

在 Laravel 模型中訪問返回變量:

Accessing the Return Variable in Laravel Model:

return $submit[0]->ObjectId;

它對我來說非常有效,希望這會幫助你們,你們不會像我一樣在這上面浪費很多時間.祝您有美好的一天.

It worked perfectly for me, Hope this will help you guys and you wont end up wasting lot of time on this just like I did. Have a great day.

這篇關于Laravel 模型 SQL Server:從存儲過程中獲取輸出參數的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

add new element in laravel collection object(在 Laravel 集合對象中添加新元素)
Creating an edit modal in Laravel 5(在 Laravel 5 中創建編輯模式)
Laravel 5.5 API resources for collections (standalone data)(用于集合的 Laravel 5.5 API 資源(獨立數據))
What is the best practice to create a custom helper function in php Laravel 5?(在 php Laravel 5 中創建自定義輔助函數的最佳實踐是什么?)
No #39;Access-Control-Allow-Origin#39; header - Laravel(沒有“Access-Control-Allow-Origin標頭 - Laravel)
Laravel Passport Route redirects to login page(Laravel Passport Route 重定向到登錄頁面)
主站蜘蛛池模板: 国产成人综合在线 | 欧美精品一区二区三区一线天视频 | www.久久国产精品 | 亚洲午夜电影 | 狠狠爱综合网 | 在线观看成年人视频 | 黄色在线免费观看视频 | 久久一视频 | 久久噜噜噜精品国产亚洲综合 | 欧美一区二区三 | 九久久| 99爱在线| 成人福利影院 | 超碰操| 欧美国产精品一区二区三区 | 久久国产福利 | 成人国产精品久久 | 爱草视频| 免费观看羞羞视频网站 | 91久久精品一区二区三区 | 国产精品久久久久久久免费大片 | 久久人体视频 | 丝袜美腿一区二区三区 | 午夜视频一区二区三区 | 欧美一级三级在线观看 | 先锋资源站 | 午夜影院操 | 国产精品美女久久久久aⅴ国产馆 | 国产一区二区精品自拍 | 欧美日韩电影一区二区 | 成年人网站在线观看视频 | 国产一区精品 | 在线成人www免费观看视频 | 欧美一级二级视频 | 欧美日韩久久精品 | 国内自拍偷拍 | 看a网站 | av免费在线播放 | 精品欧美一区二区精品久久久 | 国产精品毛片一区二区在线看 | 久草青青草 |