Reputation: 91
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.
Upvotes: 2
Views: 4867
Reputation: 26
This way work for me:
DB::select("call validate_reservation(4,'2016-04-26 20:30',1,10,1,@status,@message)");
$results = DB::select('select @status as status, @message as message ');
return dd($results[0]->message);
Upvotes: 0
Reputation: 1327
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
.
Upvotes: 3