11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 33 • MYSQL TRIGGERSFor example, to remove the au_reassign_ticket trigger, execute the following command:DROP TRIGGER au_reassign_ticket;You need the TRIGGER or SUPER privilege to successfully execute DROP TRIGGER.■ Caution When a database or table is dropped, all corresponding triggers are also deleted.Integrating Triggers into Web ApplicationsBecause triggers occur transparently, you really don’t need to do anything special to integrate theiroperation into your web applications. No<strong>net</strong>heless, it’s worth offering an example demonstrating justhow useful this feature can be in terms of both decreasing the amount of <strong>PHP</strong> code and furthersimplifying the application logic. In this section, you’ll learn how to implement the helpdesk applicationfirst depicted earlier in the “Taking Action After an Event” section.To begin, if you haven’t done so already, go ahead and create the two tables (technicians andtickets) depicted in the earlier section. Add a few appropriate rows to each, making sure that eachtickets.technician_id matches a valid technicians.technician_id. Next, create theau_reassign_ticket trigger as previously described.Recapping the scenario, submitted helpdesk tickets are resolved by assigning each to a technician. Ifa technician is out of the office for an extended period of time, he is expected to update his profile bychanging his availability status. The profile manager interface looks similar to that shown in Figure 33-1.Figure 33-1. The helpdesk account interfaceWhen the technician makes any changes to this interface and submits the form, the code presentedin Listing 33-1 is activated.Listing 33-1. Updating the Technician Profile

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

Saved successfully!

Ooh no, something went wrong!