I am creating a PHP script which imports a MySQL database into a newly created database. The script is exported from MySQLQ Workbench and contains the creation of the Triggers.
The code for importing the database works except the triggers.
Here is an example of how a trigger creation looks:
DELIMITER $$ USE `database_name`$$ CREATE DEFINER = CURRENT_USER TRIGGER `database_name`.`tablename_BEFORE_INSERT` BEFORE INSERT ON `tablename` FOR EACH ROW BEGIN IF(NEW.id IS NULL OR NEW.id = '') THEN set new.id = uuid(); END IF; END$$ DELIMITER ;
This works if i copy and paste this into PHPMyAdmin but i cannot get this executed via php ($mysqli->query(..), $mysqli->multi_query) etc...
The problem is because of the DELIMITER, i have changed the $$ to other characters but also that doesn't work. I saw other posts where people say DELIMITER isn't working via PHP but i think there has to be a way to create those triggers via PHP?