weixin_33724659 2019-04-18 14:09 采纳率: 0%
浏览 81

控制器返回空值

I have a service file where I'm running a stored procedure:

    function createCampaign($campaignName, $groupNumber){

    $stmt = \DB::connection('odbc')->getPdo()->prepare('CALL SCHEMA.INSERT_CAMPAIGN(?,?,?)');

    $stmt->bindValue(1,$campaignName, PDO::PARAM_STR);
    $stmt->bindValue(2,$groupNumber, $groupNumber==0 ? PDO::PARAM_NULL : PDO::PARAM_INT);
    $stmt->bindParam(3,$out2, PDO::PARAM_INT);

    $stmt->execute();

    return $out2;

}

When I run this stored procedure, the third parameter is giving back OUT_CAMPAIGN_ID and the expected ID, so this works. I'm returning that output variable with $out2

My controller, which calls the previous function and also expects the return back:

 public function createCampaign(Request $request)
{
    $campaignName = $request->campaignName;
    $groupNumber = $request->groupNumber;

    $campaignService = new CampaignService();
    $createCampaign = $campaignService->createCampaign($campaignName, (int) $groupNumber);

    return Response::json(["OUT_CAMPAIGN_ID" => $createCampaign]);
}

However, when I console log data.OUT_CAMPAIGN_ID in my blade, or even console log data it just gives me OUT_CAMPAIGN_ID:null

Am I doing something wrong in the way I expect it back in the controller?

Stored procedure:

BEGIN

INSERT INTO SCHEMA.TABLE(NAME,NUMBER)
VALUES (IN_NAME, IN_NUMBER);

SET OUT_ID = IDENTITY_VAL_LOCAL();

END;
  • 写回答

1条回答 默认 最新

  • weixin_33704591 2019-04-18 14:16
    关注

    It sounds like your stored procedure returns a value? I think what you need to do is more like:

    $stmt = \DB::connection('odbc')->getPdo()->prepare('CALL SCHEMA.INSERT_CAMPAIGN(?,?,?)');
    $stmt->bindValue(1,$campaignName, PDO::PARAM_STR);
    $stmt->bindValue(2,$groupNumber, $groupNumber==0 ? PDO::PARAM_NULL : PDO::PARAM_INT);
    $stmt->bindParam(3, $out2, PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT);
    $stmt->execute();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog