How to tell if the database failed to write because of the reason of duplication

Source: Internet
Author: User
Tags repetition
How can I tell if the failure to write to the database is due to duplication???
Duplicate data I need to deal with, other reasons I have to deal with it separately.


Reply to discussion (solution)

Check for duplicates before inserting!

Database has error Reporting
Echo Mysql_error ();

Can you get the reason by error? I just need to make a distinction between the reasons for the repetition, and check every record.

What repetition? Duplicate primary key ID or what?

How can I tell if the failure to write to the database is due to duplication???
Duplicate data I need to deal with, other reasons I have to deal with it separately.
When new data is added, it is necessary to determine whether there is duplicate data, stop the operation, or skip and get the duplicate primary key for easy querying.

Take MySQL for example:
MySQL is judging mysql_error.
Mysqli, Judge Mysqli_errno.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.