thinkphp5重复插入一组设置了唯一索引的数据时报错
2023-03-29 23:03:03
200
{{single.collect_count}}

找到thinkphp\library\think\db\Builder.php文件,然后找到insert函数

原 $replace ? ‘REPLACE’ : ‘INSERT’

替换后 replace?(replace ? ( replace?(replace === ‘IGNORE’ ? ‘INSERT IGNORE’ : ‘REPLACE’) : ‘INSERT’

然后在使用insert操作时

Db::name(‘XX’)->insert($value,‘IGNORE’); 这样插入相同数据的时候就会忽略报错了,返回0

原文:https://blog.csdn.net/xyf_1995/article/details/81092760

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}