9.1.5 Stored proceduresThis is NOT the latest copy of this book; click here for the latest version.
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.
Stored procedures are not supported in all DBMSs. Specifically, MySQL 4 does not support them, although they are slated for release in MySQL 5.
|
Want to see this stuff in print? PHP in a Nutshell takes the core topics covered here, adds in thousands of edits from the editorial team and myself, and combines them to make an unbeatable reference for PHP programmers at all levels.
My latest book has hundreds more tips on how to use PHP, Apache, and MySQL, plus Perl, Python, shell scripts, performance tuning, and more!
|