gpt4 book ai didi

php - 在触发器中使用定界符的 Mysql 错误

转载 作者:可可西里 更新时间:2023-11-01 07:05:08 25 4
gpt4 key购买 nike

这是我的mysql触发器语句

DELIMITER |
CREATE TRIGGER kk AFTER UPDATE
ON location FOR EACH ROW
BEGIN
IF NEW.name not in(SELECT A.name FROM filter A WHERE (NEW.name = A.name))THEN

IF NEW.location_name != OLD.location_name THEN
INSERT INTO filter(old_location_name,new_location_name)
VALUES (OLD.location_name, NEW.location_name);

ELSE

UPDATE filter SET old_location_name = OLD.location_name , new_location_name = NEW.location_name WHERE name = OLD.name;

END IF;

ELSE

UPDATE filter SET old_location_name = OLD.location_name , new_location_name = NEW.location_name WHERE name = OLD.name;


END IF;

END;|
DELIMITER ;

当我将这段代码粘贴到 phpMyadmin 时,效果很好。

在我的项目中

$sqlDrop = "DROP TRIGGER IF EXISTS `kk`";       
$resDrop = parent::_executeQuery($sqlDrop);

echo $sql = "same above delimiter trigger query";
$rs = parent::_executeQuery($sql );

现在 $sql 语句在一行中回显

 DELIMITER | CREATE TRIGGER kk AFTER UPDATE ON location FOR EACH ROW BEGIN IF NEW.name not in(SELECT A.name FROM filter A  WHERE (NEW.name = A.name))THEN IF NEW.location_name != OLD.location_name THEN INSERT INTO filter(old_location_name,new_location_name,name) VALUES (OLD.location_name, NEW.location_name);    ELSE UPDATE filter SET old_location_name = OLD.location_name , new_location_name = NEW.location_name WHERE name = OLD.name; END IF; ELSE UPDATE filter SET old_location_name = OLD.location_name , new_location_name = NEW.location_name WHERE name = OLD.name; END IF; END;| DELIMITER ;

并且不执行查询。当我将回显语句粘贴到我的 phpMyadmin 中时,它向我显示错误

enter image description here

所以可能是什么问题。这是执行触发器查询的正确方法吗?

最佳答案

不确定任何与 PHP 相关的问题,但尝试像下面那样修改您的触发器代码

DELIMITER |
CREATE TRIGGER kk AFTER UPDATE
ON location FOR EACH ROW
BEGIN
IF NEW.name not in(SELECT A.name FROM filter A WHERE NEW.name =
A.name) AND NEW.location_name != OLD.location_name THEN
INSERT INTO filter(old_location_name,new_location_name)
VALUES (OLD.location_name, NEW.location_name);
ELSE
UPDATE filter SET old_location_name = OLD.location_name ,
new_location_name = NEW.location_name WHERE name = OLD.name;
END IF;
END;|
DELIMITER ;

关于php - 在触发器中使用定界符的 Mysql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31875694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com