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.

Sample PHP program calling a stored procedure
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.

Output from our PHP example
Figure 2-20. Output from our PHP example

Get MySQL Stored Procedure Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.