php - 三个mysql触发器

标签 php mysql triggers

       delimiter //
create trigger logsupdate before update on users
for each row 
begin
  if new.pJailed <> old.pJailed then
    set new.jailtime = now();
     if new.pVIP <> old.pVIP then
    set new.TM2 = now();
         if new.pAdminLevel <> old.pAdminLevel then
    set new.TM3 = now();
  end if;
end;//
delimiter ;

为什么这不起作用?我试图遵循上一个问题的答案,但它在这里给了我错误。

MYSQL 错误

create trigger logsupdate before update on users
for each row 
begin
  if new.pJailed <> old.pJailed then
    set new.jailtime = now();
     if new.pVIP <> old.pVIP then
    set new.TM2 = now();
         if new.pAdminLevel <> old.pAdminLevel then
    set new.TM3 = now();
  end if;
end;
MySQL says: DOCUMENTATION

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 11

最佳答案

您错过了几个end if;。另外,end;// 中不需要分号。我还添加了一个 Drop Trigger If Exists 子句以避免错误,以防已存在具有该名称的重复触发器。

这是更正后的触发器(基于 OP's comments ):

delimiter //
DROP TRIGGER IF EXISTS logsupdate //
create trigger logsupdate before update on users
for each row 
begin

  if new.pJailed <> old.pJailed then
    set new.jailtime = now();
  end if;

  if new.pVIP <> old.pVIP then
    set new.TM2 = now();
  end if;

  if new.pAdminLevel <> old.pAdminLevel then
    set new.TM3 = now();
  end if;
end//
delimiter ;

关于php - 三个mysql触发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52412669/

相关文章:

php - 正则表达式 - 从字符串末尾开始搜索

php - 如何使用 htmlspecialchars 但只允许特定的 HTML 代码通过而不进行转换?

php - ShoutBox 不显示消息和用户名

php - sql选择过滤器和取消过滤器

wpf - 使用 StyleTriggers 自动隐藏进度条

php - symfony 服务容器中的回调参数

mysql - MySQL中的触发器

mysql - 使用外键是否加速表连接

MySQL:不允许从触发器返回结果集 #1415

在 PostgreSQL 9 上用 C 创建触发器