Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call stored procedure with parameters in Yii2

How to call stored procedure with parameters in Yii2?

This my stored procedure

ALTER PROCEDURE [dbo].[usp_M_Inventory#InsertData]
    @ID_Item RunNum,
    @Item_Name varchar(250),
    @ID_Mom varchar(50),
    @Item_Price float,
    @ID_Inv_Category RunNum,
    @Item_PIC1 varchar(50),
    @Item_PIC2 varchar(50),
    @Item_active BIT,
    @User UserDataType
AS
BEGIN
    SET NOCOUNT ON;

    INSERT INTO M_Inventory(ID_Item, Item_Name, ID_Mom, Item_Price, 
                            ID_Inv_Category, Item_PIC1, Item_PIC2, 
                            Item_active, insert_user, insert_date, update_user, update_date)
    VALUES (@ID_Item, @Item_Name, @ID_Mom, @Item_Price,
            @ID_Inv_Category, @Item_PIC1, @Item_PIC2,
            @Item_active, @User, GETDATE(), @User, GETDATE())
END
like image 286
Allegra Avatar asked Dec 05 '22 17:12

Allegra


1 Answers

You can use below code to call stored procedure with parameters.

$result = \Yii::$app->db->createCommand("CALL storedProcedureName(:paramName1, :paramName2)") 
                      ->bindValue(':paramName1' , $param1 )
                      ->bindValue(':paramName2', $param2)
                      ->execute();
like image 134
Chinmay Waghmare Avatar answered Dec 11 '22 10:12

Chinmay Waghmare