Reputation: 5107
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;
Upvotes: 1
Views: 66
Reputation: 64657
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();
Upvotes: 1