I am trying to automate my trigger process so that I don't have to manually create triggers for every table I want to use. Unfortunately, I get an error back saying there is a syntax error.
Here is my code
$updateTrigger = "DROP TRIGGER IF EXISTS {$table}Update
CREATE TRIGGER {$table}Update AFTER UPDATE ON $table
FOR EACH ROW
BEGIN
DECLARE N DATETIME;
SET N = now();
INSERT INTO StagesHistory (Stage, StageID, Date, Action)
VALUES ('$table', NEW.ID, N, ?);
END";
$ut = $dbh->prepare($updateTrigger);
$ut->execute(array($update));
$error = $ut->errorInfo();
Evaluating $error
returns this error message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TRIGGER TranslationUpdate AFTER UPDATE ON Translation FOR EACH R' at line 2
I can't figure out what error it's talking about. What's the problem, and how do I fix it?