-1

我在php中编写了一个简单的触发器,这是我的代码

$triggerQuery = 
"DELIMITER  && 
create or replace Trigger insert_room_type after insert on hotel for each row
begin 
insert into room_type values(NEW.hotelID,'Single',0,NULL);
insert into room_type values(NEW.hotelID,'Double',0,NULL);
insert into room_type values(NEW.hotelID,'Standard',0,NULL);
insert into room_type values(NEW.hotelID,'Superior',0,NULL);
end && DELIMITER ;";

但是,当代码运行时,只执行了第一个插入(4 个),谁能告诉我我做错了什么?提前谢谢。

顺便说一句,room_type 的主键是 hotelID 和 RoomCategory(这是第二列),所以不会有任何主键违规吗?

4

1 回答 1

0

从未听说过使用 PHP 创建触发器。而且它们只被创建一次!

要修复您的错误,您必须更改分隔符。否则 MySQL 认为触发器已完成第一个;.

DELIMITER $$
create Trigger insert_room_type after insert on hotel for each row
begin 
insert into room_type values(NEW.hotelID,'Single',0,NULL);
insert into room_type values(NEW.hotelID,'Double',0,NULL);
insert into room_type values(NEW.hotelID,'Standard',0,NULL);
insert into room_type values(NEW.hotelID,'Superior',0,NULL); 
end $$
DELIMITER ;
于 2013-03-28T15:35:58.297 回答