我有两个字段 Aadhaar number
和 PAN Number
字段 UNIQUE
到数据库中
我的要求是,每当我插入一些重复的条目时,它只会给我一个错误
Could Not Enter, Duplicate Aadhaar and/or PAN Number
MySQL 有什么方法可以抛出这种错误吗?
最佳答案
您需要找到错误代码。重复键为 1062
。您可以像下面的代码一样处理它。
mysqli_query($con,'INSERT INTO ...');
if (mysqli_errno($con) == 1062) {
print 'Could Not Enter, Duplicate Aadhaar and/or PAN Number';
}
use mysqli_errno() to retrieve the error code. Note that this function only returns the error code from the most recently executed MySQL function.
关于php - 如何在 MySQL 中重复插入行时抛出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51322936/