这是我第一次尝试使用触发器,我只是快速做了一些测试,但它给我一个错误。这是我的触发器(为插入后设置)
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 );
我收到以下错误:
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
怎么了?
最佳答案
你可以试试这个(只需从表名中删除引号):
INSERT INTO logs
( staff_id, table_name, table_id, controller )
VALUES
( NEW.staff_id, 'acl', NEW.id, @controller );
或者你可以使用反引号
INSERT INTO `logs`
( staff_id, table_name, table_id, controller )
VALUES
( NEW.staff_id, 'acl', NEW.id, @controller );
关于带有 Sequel Pro 的 MySQL 触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20503726/