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
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With