Conclusion
In this chapter we presented a brief "getting started" tutorial that introduced you to the basics of MySQL stored programs. We showed you how to:
- Create a simple "Hello World" stored procedure.
- Define local variables and procedure parameters.
- Perform conditional execution with the IF statement.
- Perform iterative processing with simple loops.
- Include SQL statements inside stored procedures, including how to perform row-at-a-time processing with cursors.
- Call a stored program from another stored program.
- Create a stored function (and differentiate stored functions from stored procedures).
- Create a trigger on a table to automate denormalization.
- Call a stored procedure from PHP.
Figure 2-19. Sample PHP program calling a stored procedure
You may now be tempted to put down this book and start writing MySQL stored programs. If so, we congratulate you on your enthusiasm. May we suggest, however, that you first spend some time reading more detailed explanations of each of these areas of functionality in the following chapters? That way, you are likely to make fewer mistakes and write higher-quality code.
Figure 2-20. Output from our PHP example