Answer the question
In order to leave comments, you need to log in
Adding a mysql trigger from PHP (with delimiter change) possible?
Good afternoon friends! I need to interact with mysql triggers (add/remove) using PHP. Please, prompt by what means it is realizable. Error 1064 (syntax), but it's understandable - there can be only one muscle command in a request from PHP. How to bypass it? Only .. exec() remained in my head?
I would be very grateful. Thank you!
DELIMITER //
CREATE TRIGGER before_update_elem BEFORE UPDATE ON dc_operations FOR EACH ROW BEGIN
CASE
WHEN (...) THEN
INSERT INTO ...
WHEN (...) THEN
INSERT INTO ...
ELSE BEGIN END;
END CASE;
END//
DELIMITER ;
Answer the question
In order to leave comments, you need to log in
Just don't use DELIMITER:
<?php
$d = new \PDO('mysql:host=mysql;dbname=test', 'username', 'password');
$sql = <<<SQL
CREATE TRIGGER before_update_elem BEFORE UPDATE ON dc_operations FOR EACH ROW BEGIN
CASE
WHEN (...) THEN
INSERT INTO ...
WHEN (...) THEN
INSERT INTO ...
ELSE BEGIN END;
END CASE;
END
SQL;
$d->exec($sql);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question