0

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.

1
  • What database server are you using? Is that MySQL syntax? Commented Jun 5, 2012 at 23:43

1 Answer 1

1

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); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.