zhekaus
zhekaus

Reputation: 3194

How to call MySQL stored procedure with OUT parameter in 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?

Upvotes: 4

Views: 5382

Answers (1)

user1669496
user1669496

Reputation: 33068

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.

Upvotes: 6

Related Questions