Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute Stored Procedure from Laravel

I need to execute a stored procedure after my form submits data. I have the stored procedure working like I want it, and I have my form working properly. I just do not know the statement to execute the sp from laravel 5.

it should be something like this: execute my_stored_procedure. but I can not seem to find anything like that online.

like image 542
Jordan Davis Avatar asked Dec 28 '15 16:12

Jordan Davis


People also ask

How do I create a stored procedure in MySQL?

Create a simple stored procedure. DELIMITER ; To create the MySQL Stored Procedure, open the MySQL workbench Connect to the MySQL Database copy-paste the code in the query editor window click on Execute. You can view the procedure under stored procedures.

What is the stored procedure in MySQL?

A stored procedure is a prepared SQL code that you can save, so the code can be reused over and over again. So if you have an SQL query that you write over and over again, save it as a stored procedure, and then just call it to execute it.

What is stored procedure in database?

A stored procedure is a set of Structured Query Language (SQL) statements with an assigned name, which are stored in a relational database management system (RDBMS) as a group, so it can be reused and shared by multiple programs.


1 Answers

Try something like this

DB::select('exec my_stored_procedure("Param1", "param2",..)'); 

or

DB::select('exec my_stored_procedure(?,?,..)',array($Param1,$param2)); 

Try this for without parameters

DB::select('EXEC my_stored_procedure') 
like image 123
Pரதீப் Avatar answered Oct 15 '22 06:10

Pரதீப்