11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 32 • STORED ROUTINESprocedure to determine when the iteration of a result set had completed. Two declarations wererequired, a variable named finished and a handler for the NOT FOUND condition:DECLARE finished INTEGER DEFAULT 0;DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished=1;Once the iteration loop was entered, finished was checked with each iteration, and if it was set to 1,the loop would be exited:IF finished=1 THENLEAVE calcloop;END IF;<strong>MySQL</strong> supports numerous conditions that can be reacted to as necessary. See the <strong>MySQL</strong>documentation for more details.Integrating Routines into Web ApplicationsThus far, all the examples have been demonstrated by way of the <strong>MySQL</strong> client. While this is certainly anefficient means for testing examples, the utility of stored routines is drastically increased by the ability toincorporate them into your application. This section demonstrates just how easy it is to integrate storedroutines into your <strong>PHP</strong>-driven web application.Creating the Employee Bonus InterfaceReturning to the multistatement stored function example involving the calculation of employeebonuses, it was mentioned that a web-based interface was offered to enable employees to track theiryearly bonus in real time. This example demonstrates just how easily this is accomplished using thecalculate_bonus() stored function.Listing 32-1 presents the simple HTML form used to prompt for the employee ID. Of course, in areal-world situation, such a form would also request a password; however, for the purposes of thisexample an ID is sufficient.Listing 32-1. The Employee Login Form (login.php)Employee ID:Listing 32-2 receives the information provided by login.php, using the provided employee ID andcalculate_bonus() stored function to calculate and display the bonus information.Listing 32-2. Retrieving the Present Bonus Amount (viewbonus.php)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!