I am trying to pass the data from the stored procedure, from the controller, but I don't know what is generating an error, which only creates the record in the table that I want, but does not save any data in the table.
AP:
CREATE PROCEDURE movimientos_stock (
IN usuario_fk BIGINT,
IN producto_fk BIGINT,
IN area_fk BIGINT,
IN tipo_area_fk BIGINT,
IN tipo_movimiento VARCHAR(100),
IN created_at DATETIME)
BEGIN
INSERT INTO `movimientos`(usuario_fk, producto_fk, area_fk, tipo_area_fk, tipo_movimiento, created_at)
VALUES (usuario_fk, producto_fk, area_fk, tipo_area_fk, tipo_movimiento, created_at);
END;
CONTROLLER
In the controller I use it like this:
DB::unprepared("CALL movimientos_stock($usuario_fk, $producto_fk, $area_fk, $tipo_area_fk, $tipo_movimiento, $created_at)");
The variables I am adding are already declared and if they are receiving the data I need.
As you can see, it registers me, but it doesn't save anything.
The issue is that if we review the documentation you can notice that the method
unprepared(....)
is designed to execute queries where no link between markers and variables will be made ( this may be the cause of the failure ).So, since your PA is not oriented to return a result of the executed operation, you can opt for the method:
statement(...........)
considering that it receives 2 arguments:A string with the query to execute (necessary)
An array with the variables with which the binding will be used in the query (optional)
Don't forget to import to DB like this: