Procedures are control blocks created in the database in order to optimize a function that will be used at various times, they work so similar to the methods in programming. In MySQL, procedures are used to facilitate routine transaction with the bank and also to help in the process of data manipulation when working with desktop or web interfaces.
To create a procedure in MySQL is necessary to use some commands that together enable its inception, the syntax is as follows:
CREATE PROCEDURE ‘[procedure name]’ ([Parameters])
As a practical example we will perform a SELECT with filters from a variable informed user.
CREATE PROCEDURE ‘sp_product’ (IN _id INT)
Where id_product = _id
Note that before the variable declaration syntax is used IN stating that this variable will be informed by the user, another way to use variables is to use the command OUT where this variable is returned with some value to the user.
To use the procedure established just use the call command and then the procedure name with parameters, if it has.
Understand the workings of MySQL is paramount for projects that want to increase its cost-effective, learn more about the advantages of PHP combined with MySQL on our official site by clicking the link above.