2017-11-15 6 views
0

'type', 'receiver_id', 'confirm'및 'id'필드가있는 'comments'테이블이 있습니다. 코멘트 섹션이있는 오브젝트에는 세 가지 유형이 있습니다. 주석 뒤에 트리거가 해당 테이블의 개체 수를 늘리는 지 확인하십시오. 마이그레이션IF 및 IF ELSE 조건이있는 Mysql 트리거

DB::unprepared('CREATE TRIGGER comment_confirm 
     AFTER UPDATE ON comments FOR EACH ROW 
     BEGIN 
      IF OLD.confirm = 0 AND NEW.confirm = 1 THEN 
       IF OLD.type = profile THEN 
        UPDATE profiles SET comments = comments + 1 WHERE user_id = OLD.reciever_id; 
       ELSE IF OLD.type = blog THEN 
        UPDATE blogs SET comments = comments + 1 WHERE user_id = OLD.reciever_id; 
       ELSE IF OLD.type = topic THEN 
        UPDATE topics SET comments = comments + 1 WHERE user_id = OLD.reciever_id; 
       END IF; 
      END IF; 
     END 
     '); 

오류는 다음과 같습니다

그렇지
[PDOException] 
    SQLSTATE[42000]: Syntax error or access violation: 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 '' at line 13 

답변

1

OLD.type = 프로필 문자열 비교에 대한 작은 따옴표에 있어야 제대로 보이지 않는 경우 (공백) ELSEIF해서는 안 경우.