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])

BEGIN

[Commands]

END

As a practical example we will perform a SELECT with filters from a variable informed user.

CREATE PROCEDURE ‘sp_product’ (IN _id INT)

BEGIN

Select *

From products

Where id_product = _id

END

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.

call sp_product(1)

mysql

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.

You might also like…

PROCESAMIENTO AJAX EN SCRIPTCASE

Ajax en los formularios de Scriptcase puede usarse para recargar un campo de tipo de select basado e...

IMPORTAR IMAGENES DE LA BASE DE DATOS Y UTILIZAR CLASES DE BOOSTRAP

Como muchas personas ya saben, Bootstrap es una biblioteca de front-end libre y de código abierto p...

TENDENCIAS DE DESARROLLO WEB PARA 2017

Usted verá en este post tendencias para 2017 en Diseño Web, en el medio digital y en el desarrollo...

Comment this post

Get new posts, resources, offers and more each week.

We will use the information you provide to update you about our Newsletter and Special Offers. You can unsubscribe any time you want by clinck in a link in the footer of any email you receive from us, or by contacting us at sales@scriptcase.net. Learn more about our Privacy Police.