Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL:创建触发器时出现语法错误_Php_Mysql - Fatal编程技术网

Php MySQL:创建触发器时出现语法错误

Php MySQL:创建触发器时出现语法错误,php,mysql,Php,Mysql,为什么我的sql语法抛出错误 CREATE TRIGGER info AFTER INSERT ON inbox FOR EACH ROW BEGIN if SUBSTRING(new.TextDecoded,1,6)='telkom' then INSERT INTO outbox ( DestinationNumber, Coding, TextDecoded, CreatorID )VALUES ( new.SenderNumber, 'Default_No_Compression', (

为什么我的sql语法抛出错误

CREATE TRIGGER info
AFTER INSERT ON inbox
FOR EACH ROW BEGIN if SUBSTRING(new.TextDecoded,1,6)='telkom' then
INSERT INTO outbox ( DestinationNumber, Coding, TextDecoded, CreatorID )VALUES ( new.SenderNumber, 'Default_No_Compression', (SELECT nama from data_dosen WHERE kode = SUBSTRING(new.TextDecoded,8,10)), '1');

else
INSERT INTO outbox (DestinationNumber, Coding, TextDecoded, CreatorID) VALUES (new.SenderNumber, 'Default_No_Compression', 'Maaf format sms Anda salah. Ketik telkom<spasi>kode dosen', '1');

end if;

END$$
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以了解第4行附近要使用的正确语法


触发器之前没有分隔符定义。分隔符通知MySQL哪些字符将结束触发器。没有它,MySQL将分号作为默认分隔符,并在代码中的第一个分号时失败。看看这个:

DELIMITER $$
CREATE TRIGGER info
AFTER INSERT ON inbox
FOR EACH ROW BEGIN if SUBSTRING(new.TextDecoded,1,6)='telkom' then
    INSERT INTO outbox ( DestinationNumber, Coding, TextDecoded, CreatorID )VALUES ( new.SenderNumber, 'Default_No_Compression', (SELECT nama from data_dosen WHERE kode = SUBSTRING(new.TextDecoded,8,10)), '1');

else
    INSERT INTO outbox (DestinationNumber, Coding, TextDecoded, CreatorID) VALUES (new.SenderNumber, 'Default_No_Compression', 'Maaf format sms Anda salah. Ketik telkom<spasi>kode dosen', '1');

end if;

END$$
DELIMITER ;
您可能需要在触发器之前使用分隔符语句。