I mean can be inserted to return true, can not return false, but can not be inserted when the direct display of this
Negative on My Code:
Reply content:
I mean can be inserted to return true, can not return false, but can not be inserted when the direct display of this
Negative on My Code:
Naturally, it is possible.
You can use the following three ways to make a page jump in combination with your business needs
Ignore: A repetition is ignored.
INSERT IGNORE INTO `table_name` (`email`, `phone`, `user_id`) VALUES ('test9@163.com', '99999', '9999');
Replace: Delete old data and add new data if duplicate
REPLACE INTO `table_name`(`col_name`, ...) VALUES (...);REPLACE INTO `table_name` (`col_name`, ...) SELECT ...;REPLACE INTO `table_name` SET `col_name`='value'
On duplicate key update: Duplicate update
INSERT INTO `table` (`a`, `b`, `c`) VALUES (1, 2, 3), (4, 5, 6) ON DUPLICATE KEY UPDATE `c`=VALUES(`a`)+VALUES(`b`);
Recommended article: MySQL avoid duplicate insert record method (Ignore,replace,on DUPLICATE KEY UPDATE)
You can take this exception Catch yourself, and then return TRUE or False