Creating MYSQL Stored Procedures With The Command Line
Stored procedures require a different set of methods from typical mysql queries, but, there are only a few which need to be implemented. For example, you need to create a procedure with 'CREATE PROCEDURE', you use 'BEGIN' and 'END' around the declared variables and mysql query and you declare and set variables. Finally, you use a delimiter so that mysql will run all of the code; rather than an execute when it sees a semi-colon(;). The examples below show how to make simple stored procedures.
Why use stored procedures?
Using stored procedures allows a programmer to create custom mysql queries that can be used throughout variious scripts without having to hard code each and every time time. Essentially, using stored procedures can reduce redundancy.
The simple code below shows how you can call a stored procedure from a php script.