Reputation: 255
I have very long SQL file which includes $variable
in format like:
DELIMITER $$
DROP TRIGGER IF EXISTS `$variable` $$
CREATE TRIGGER `TEMP` BEFORE INSERT ON `5_2012`
FOR EACH ROW BEGIN
set NEW.chour = timediff(NEW.exit, NEW.enter);
set NEW.total = timediff(NEW.exit, NEW.enter);
...
I need a way to execute this script each time with different table names ($variable
).
I am using MySQL.
Upvotes: 0
Views: 1044
Reputation: 406
Change your .sql file into a .php script Add a header to the top, and add the mime type. If i can remember correctly, it's application/x-sql. Echo out each variable.
<?php
header("Content-type: application/x-sql");
?>
DELIMITER $$
DROP TRIGGER IF EXISTS `<?= $variable; ?>` $$
CREATE TRIGGER `TEMP` BEFORE INSERT ON `5_2012`
FOR EACH ROW BEGIN
set NEW.chour = timediff(NEW.exit, NEW.enter);
set NEW.total = timediff(NEW.exit, NEW.enter);
Upvotes: 1