What I mean is that if it can be inserted, it will return true, if it cannot be inserted, it will return false, but when it cannot be inserted, it will directly display this
Add my code:
What I mean is that if it can be inserted, it will return true, if it cannot be inserted, it will return false, but when it cannot be inserted, it will directly display this
Add my code:
Of course it is possible.
You can use the following three methods to jump to the page based on your business needs
Ignore: Ignore duplicates.
<code>INSERT IGNORE INTO `table_name` (`email`, `phone`, `user_id`) VALUES ('test9@163.com', '99999', '9999'); </code>
Replace: If there are duplicates, delete the old data and add new data
<code>REPLACE INTO `table_name`(`col_name`, ...) VALUES (...); REPLACE INTO `table_name` (`col_name`, ...) SELECT ...; REPLACE INTO `table_name` SET `col_name`='value' </code>
On duplicate key update: If there are duplicates, update
<code>INSERT INTO `table` (`a`, `b`, `c`) VALUES (1, 2, 3), (4, 5, 6) ON DUPLICATE KEY UPDATE `c`=VALUES(`a`)+VALUES(`b`); </code>
Recommended article: MySql method to avoid repeated insertion of records (ignore, Replace, ON DUPLICATE KEY UPDATE)
You can catch this Exception yourself and return true or false