Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call MySQL stored procedure with OUT parameter in Laravel

Tags:

mysql

laravel

Does anybody know how to call MySQL stored procedure with OUT parameter in Laravel?

Let’s say I have:

DB::statement('CALL sp_user_add(:name, :email, :password, :key, @res, @id);',
    array(
        $name,
        $email,
        $password,
        $key
    )
);

How to get values of @res and @id?

like image 639
zhekaus Avatar asked Sep 07 '25 14:09

zhekaus


1 Answers

I'm getting my information from http://www.mysqltutorial.org/mysql-stored-procedures-return-multiple-values/ and this is untested, but it looks as though you will need to issue an additional statement to grab those values...

Try adding this after...

$results = DB::select('select @res as res, @id as id');

And then results are in $results[0]->res and $results[0]->id.

like image 122
user1669496 Avatar answered Sep 10 '25 03:09

user1669496