简体   繁体   中英

MySQL Trigger with Sequel Pro

This is my first attempt at using triggers, and I just made something quickly for test, but it gives me an error. Here is my trigger (set for AFTER INSERT)

IF NEW.controller = 'index' THEN
    SET @controller = 'index';
ELSE
    SET @controller = 'other';
END IF;

INSERT INTO 'logs'
    ( staff_id, table_name, table_id, controller )
VALUES
    ( NEW.staff_id, 'acl', NEW.id, @controller );

I get the following error:

MySQL said: 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 'INSERT INTO 'logs' ( staff_id, table_name, table_id, controller ) VALUES ( NEW' at line 7

What is the matter?

You may try this(Just remove the quotes from table name):

INSERT INTO logs
    ( staff_id, table_name, table_id, controller )
VALUES
    ( NEW.staff_id, 'acl', NEW.id, @controller );

or you may use the backticks

INSERT INTO `logs`
    ( staff_id, table_name, table_id, controller )
VALUES
    ( NEW.staff_id, 'acl', NEW.id, @controller );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM