Delphi For PHP Forums       


Go Back   Delphi-PHP Forums > Programming > PHP - Code Snippets
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

PHP - Code Snippets Functional Code Snippets that other people may find useful. Post them here!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 7th July 2009, 18:21
D4PHP Engineer
 
Join Date: Jul 2007
Posts: 431
classic is on a distinguished road
Default MYSQL triggers

I have been playing with MYSQL triggers and the following allows you to populate another table with data from an existing table on an insert, update or delete.

In navicat goto design mode.
There is tab for triggers.
Name the trigger
Set Fires on to Before or After
Then select insert, update or delete


Trigger for update example

IF OLD.defence != NEW.defence
THEN
INSERT INTO triggers1
(defence,EquipmentID)
VALUES
(
NEW.defence,OLD.EquipmentID
);
END IF
('OLD.' is the previous value of the field defence . 'New.' is the new value of the field defence )

so when the defence value is changed I get the new value of defence & the
value of EquipmentID posted into the triggers1 table.

trigger for insert example


INSERT INTO triggers1
(imagetype,EquipmentID)
VALUES
(
NEW.EquipmentStateID,NEW.EquipmentID
)

I get the new values of EquipmentStateID & EquipmentID inserted into the triggers1 table.


I have some large tables that are updated with certain values. When they are updated we have to run some code to send out an SMS message. So rather than polling the large tables I poll the triggers1 table process the action then remove the record. So the triggers1 table remains fairly small.

Hope this is of help to you ans all.


Cheers

SteveW
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 8th July 2009, 13:14
D4PHP Engineer
 
Join Date: Jul 2007
Posts: 431
classic is on a distinguished road
Default

Another good resource is MySQL Reference Manual for version 5.0.3-alpha - 20 Triggers
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 03:36.




Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 ©2009, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use