我有一个运行存储过程的服务文件:
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;
}
当我运行此存储过程时,第三个参数将返回OUT_CAMPAIGN_ID
和期望的ID,因此可以正常工作。我用$out2
我的控制器,它调用前一个函数,并且还希望返回:
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]);
}
但是,当我在刀片中管理日志data.OUT_CAMPAIGN_ID
甚至控制台日志data
时,它只会给我OUT_CAMPAIGN_ID:null
我在控制器中期望的方式做错了吗?
存储过程:
BEGIN
INSERT INTO SCHEMA.TABLE(NAME,NUMBER)
VALUES (IN_NAME, IN_NUMBER);
SET OUT_ID = IDENTITY_VAL_LOCAL();
END;
答案 0 :(得分:1)
听起来您的存储过程返回了值?我认为您需要做的更像是:
$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();