Stored procedures

If you find yourself performing the same queries again and again, it might help to use stored procedures. These are like named functions within a DBMS - you define a sequence of instructions to perform, and give it a name. Whenever you want that same set of instructions to be performed, you simply run the procedure - the results often come back faster because the DBMS has already prepared the query in advance, and so knows how to run it quickly.

One big advantage to stored procedures is that they remain on the DBMS - if you want to change a procedure so that it does something different, you need only change it once, on the server, to have all the programming code that calls it updated also.


Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Triggers >>

Previous chapter: Transactions

Jump to:


Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.