1

I wanted to create a TRIGGER for my database. The code is that:

DELIMITER ;

DROP TRIGGER  IF EXISTS `spi_financial_request_AINS`;

DELIMITER $$

CREATE
    DEFINER = CURRENT_USER 
    TRIGGER `spi_financial_request_AINS` AFTER INSERT ON   `spi_financial_request` 
    FOR EACH ROW BEGIN    
            DECLARE ev_id INT;       
                IF check_audit('spi_financial_request')=1 THEN  
              INSERT INTO spi_audit_event(table_name, record_id,event_type,user_id)
              VALUES('spi_financial_request',new.id,'INS',@user_id);
                  SELECT LAST_INSERT_ID() INTO ev_id;
INSERT INTO spi_audit_data(event_id,column_name,new_value)VALUES(ev_id,'id',new.id);
INSERT INTO spi_audit_data(event_id,column_name,new_value)VALUES(ev_id,'request_id',new.request_id);
INSERT INTO spi_audit_data(event_id,column_name,new_value)VALUES(ev_id,'payment_type_id',new.payment_type_id);
            END IF;
        END;
$$

DELIMITER ;

I've executed it on my local site (using SQLyog and 5.6.29 version of MySQL). It works.

But when I tried to use it on DEV server (using PHPMyAdmin and 5.6.32 version of MySQL), I've got an error:

#1064 - 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 'DELIMITER' at line 1

I really don't understand what is wrong.

Arulkumar
  • 12,966
  • 14
  • 47
  • 68
  • The default delimiter is already `;` try `DELIMITER $$` in the first line so the the `DROP TRIGGER....` will also work – RiggsFolly Sep 07 '16 at 12:25
  • Your trigger works fine on my system. Try not doing anything with DELIMITER as I hear that is not used with PHPMyAdmin – Drew Sep 07 '16 at 12:27

1 Answers1

0

DELIMITER is a Mysql console command, You can't use it in phpmyadmin. To set the delimiter in phpmyadmin, see this other answer

Community
  • 1
  • 1
Stivan
  • 1,128
  • 1
  • 15
  • 24