Guest User

16. Emails Trigger

a guest
Feb 21st, 2018
279
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE IF NOT EXISTS `notification_emails` (
  2. `id` INT PRIMARY KEY AUTO_INCREMENT,
  3. `recipient` INT,
  4. `subject` TEXT,
  5. `body` TEXT
  6. );
  7.  
  8. TRUNCATE TABLE `notification_emails`;
  9.  
  10. DROP TRIGGER IF EXISTS `tr_logs_change_email`;
  11.  
  12. DELIMITER $$
  13.  
  14. CREATE TRIGGER `tr_logs_change_email`
  15. AFTER INSERT ON `logs`
  16. FOR EACH ROW
  17. BEGIN
  18. INSERT `notification_emails`( `recipient`,`subject`,`body`)
  19. VALUES (`account_id`,CONCAT_WS(' ','Balance change for account:', `account_id`),
  20. CONCAT_WS(' ','On',NOW(),'your balance was changed from',`old_sum`,'to',`new_sum`,'.'));
  21. END $$
  22.  
  23. DELIMITER ;
RAW Paste Data