gpt4 book ai didi

php - 是否可以将触发器错误消息显示到网页?

转载 作者:太空狗 更新时间:2023-10-29 14:17:04 25 4
gpt4 key购买 nike

我在特定条件下触发,如果条件:false 发生错误。我应该将数据库触发器中发生的错误消息显示到 HTML 网页以通知用户!

CREATE TRIGGER check_trigger BEFORE INSERT ON your_table
FOR EACH ROW
BEGIN
IF (NEW.name = NEW.firstname) THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'same names error. Insertion canceled';
END IF;
END

如何在网页上显示SET MESSAGE_TEXT=""?如果其他方式不行

最佳答案

可以看看the documentation here .

它说:

The error values that are accessible after SIGNAL executes are the SQLSTATE value raised by the SIGNAL statement and the MESSAGE_TEXT and MYSQL_ERRNO items. These values are available from the C API:

mysql_sqlstate() returns the SQLSTATE value.

mysql_errno() returns the MYSQL_ERRNO value.

mysql_error() returns the MESSAGE_TEXT value.

因为我猜你正在使用 PHP,你可以试试

if (!$mysqli->query("INSERT INTO your_table SET name='a', firstname='a'")) {
printf("Error message: %s\n", $mysqli->error);
}

关于php - 是否可以将触发器错误消息显示到网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56852641/

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