MySQL Event Error Using PHP

MYSQL EVENT or Something else ? trying to track clicks for links

Don't use the event scheduler, use a trigger that runs when updating the links table:

DELIMITER $$
CREATE TRIGGER link_completed
BEFORE UPDATE ON links
FOR EACH ROW
BEGIN
IF NEW.bought = 0
THEN SET NEW.status = 'completed';
END IF;
END; $$
DELIMITER ;

Connection between MySQL Event and Table

Make a trigger like this:

SET @ename:='rec';
SET @sql_text = concat('CREATE TRIGGER delete_invoice_event AFTER DELETE on TABLE FOR EACH ROW BEGIN DROP EVENT IF EXISTS ', @ename ,'old.id END');

PREPARE stmt FROM @sql_text;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

You have to use PREPARE statement, because your event name is dynamic, based on the deleted record id that would be accessible by old.id



Related Topics



Leave a reply



Submit