Syntax error, Mysql trigger executed by php

Asked

Viewed 22 times

0

Could someone please tell me where I’m going wrong with my Rigger’s creation

Trigger

$sql = "DELIMITER $$
                CREATE TRIGGER produtos_movto_insert AFTER INSERT ON produtos_movto
                            FOR EACH ROW
                            BEGIN
                                IF NEW.prmv_maismenos = '+' THEN
                                    UPDATE produtos SET prod_qte_estoque = (prod_qte_estoque + NEW.prmv_qte) WHERE idprodutos = NEW.prmv_idprodutos;         
                                END IF;

                                IF NEW.prmv_maismenos = '-' THEN
                                    UPDATE produtos SET prod_qte_estoque = (prod_qte_estoque - NEW.prmv_qte) WHERE idprodutos = NEW.prmv_idprodutos;
                                END IF;                                         
                END
                $$";

Error

Erro: 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 'DELIMITER $$ CREATE TRIGGER produtos_movto_insert AFTER INSERT ON produtos' at line 1

It is stored in a php variable and is executed by php

  • you can tell which is the error, the line?

  • @Ricardopunctual I edited the question and put the error there

  • I’m a little rusty, but I think we’re missing one ; after the END and before the $$ (at the end of the syntax)?

  • @Ricardopunctual I just put the ; last END but the error persisted

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.