user2540080 user2540080 - 1 year ago 178
MySQL Question

Using stored procedure with an OUT parameter in Laravel

I'm having a problem calling a stored procedure that has two OUT parameters. I cannot access them.

Here is my procedure's first line:

PROCEDURE `validate_reservation`(IN people INT, IN r_date DATETIME,IN place_id INT,IN max_people INT,IN more_people TINYINT(1),OUT r_status CHAR(20),OUT message CHAR(100))

And here is how I call it from Laravel 5:

DB::statement("call validate_reservation(4,'2016-04-26 20:30',1,10,1,$status,$message)");

I don't know if I have to pass two empty variables and they will turn the values of the output or if that is the return of the statement.

If I pass two empty variables Laravel tells me they are not defined. If I don't pass them, Laravel tells me the procedure is waiting for 7 parameters instead of 5.

Answer Source

With OUT parameters, you're dealing with MySQL variables - these are prefixed with @.

So, use @status, @message instead of $status, $message. Also, you may want to use binding to pass the other values.

These won't populate PHP variables in any case. If you want to get them in PHP, you'll need to SELECT them, e.g. SELECT @status, @message using DB::select.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download