{"id":26687,"date":"2016-09-14T09:14:14","date_gmt":"2016-09-14T07:14:14","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=26687"},"modified":"2016-09-14T09:14:14","modified_gmt":"2016-09-14T07:14:14","slug":"mysql-php-and-integrity-constraint-violation-1062-duplicate-entry","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/","title":{"rendered":"MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p><a href=\"http:\/\/afilina.com\/\">Anna Filina<\/a> blogs about <a href=\"http:\/\/afilina.com\/mysql-duplicate-not-really\/\">an interesting problem<\/a> she encountered with when working on a PHP and MySQL project:<\/p>\n<blockquote><p>MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column.<\/p>\n<p>I gave up on logic and simply dumped the contents of the problematic column for every record. I found that there was a record with and without an accent on one of the characters. PHP saw each as a unique value, but MySQL did not make a distinction, which is why it complained about a duplicate value. It\u2019s a good thing too, because based on my goal, these should have been treated as duplicates.<\/p><\/blockquote>\n<p>She also mentions two possible solutions to the problem:<\/p>\n<blockquote><p>My solution was to substitute accented characters before filtering duplicates in the code. This way, similar records were rejected before they were sent to the database.<\/p><\/blockquote>\n<p>and<\/p>\n<blockquote><p>As pointed out in the comments, a more robust and versatile solution would be to check the collation on the column.<\/p><\/blockquote>\n<p>I&#8217;m sure this will come in handy one day.<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"MySQL, PHP and \"Integrity constraint violation: 1062 Duplicate entry\" #PHP #MySQL #unicode #databases #WebDev","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false,"_links_to":"","_links_to_target":""},"categories":[1,18,62,1334],"tags":[1559,3066,38,23,1330],"keyring_services":[],"class_list":["post-26687","post","type-post","status-publish","format-standard","hentry","category-general","category-programming","category-technology","category-web-work","tag-databases","tag-mysql","tag-php","tag-unicode","tag-web-development"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.8 - aioseo.com -->\n\t<meta name=\"description\" content=\"Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Leonid Mamchenkov\"\/>\n\t<meta name=\"google-site-verification\" content=\"VHvdD0_usx1_4DzKy_QCVcICVgX2EgA2ybELT-wl7kQ\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.8\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Leonid Mamchenkov - Life, universe, and everything else\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"MySQL, PHP and \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d - Leonid Mamchenkov\" \/>\n\t\t<meta property=\"og:description\" content=\"Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"1024\" \/>\n\t\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2016-09-14T07:14:14+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2016-09-14T07:14:14+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/MamchenkovBlog\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@mamchenkov\" \/>\n\t\t<meta name=\"twitter:title\" content=\"MySQL, PHP and \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d - Leonid Mamchenkov\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the\" \/>\n\t\t<meta name=\"twitter:creator\" content=\"@mamchenkov\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#blogposting\",\"name\":\"MySQL, PHP and \\u201cIntegrity constraint violation: 1062 Duplicate entry\\u201d - Leonid Mamchenkov\",\"headline\":\"MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;\",\"author\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#person\"},\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#articleImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Leonid Mamchenkov\"},\"datePublished\":\"2016-09-14T09:14:14+02:00\",\"dateModified\":\"2016-09-14T09:14:14+02:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#webpage\"},\"articleSection\":\"All, Programming, Technology, Web work, databases, MySQL, PHP, Unicode, web development\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/#listItem\",\"position\":2,\"name\":\"Technology\",\"item\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/programming\\\/#listItem\",\"name\":\"Programming\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/programming\\\/#listItem\",\"position\":3,\"name\":\"Programming\",\"item\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/programming\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#listItem\",\"name\":\"MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/#listItem\",\"name\":\"Technology\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#listItem\",\"position\":4,\"name\":\"MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/category\\\/technology\\\/programming\\\/#listItem\",\"name\":\"Programming\"}}]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#person\",\"name\":\"Leonid Mamchenkov\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#personImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Leonid Mamchenkov\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/#author\",\"url\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/\",\"name\":\"Leonid Mamchenkov\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g\",\"width\":96,\"height\":96,\"caption\":\"Leonid Mamchenkov\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#webpage\",\"url\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/\",\"name\":\"MySQL, PHP and \\u201cIntegrity constraint violation: 1062 Duplicate entry\\u201d - Leonid Mamchenkov\",\"description\":\"Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \\u201cIntegrity constraint violation: 1062 Duplicate entry\\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/2016\\\/09\\\/14\\\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/author\\\/leonid\\\/#author\"},\"datePublished\":\"2016-09-14T09:14:14+02:00\",\"dateModified\":\"2016-09-14T09:14:14+02:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#website\",\"url\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/\",\"name\":\"Blog of Leonid Mamchenkov\",\"description\":\"Life, universe, and everything else\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/mamchenkov.net\\\/wordpress\\\/#person\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"MySQL, PHP and \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d - Leonid Mamchenkov","description":"Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the","canonical_url":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"google-site-verification":"VHvdD0_usx1_4DzKy_QCVcICVgX2EgA2ybELT-wl7kQ","miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#blogposting","name":"MySQL, PHP and \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d - Leonid Mamchenkov","headline":"MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;","author":{"@id":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/#author"},"publisher":{"@id":"https:\/\/mamchenkov.net\/wordpress\/#person"},"image":{"@type":"ImageObject","@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#articleImage","url":"https:\/\/secure.gravatar.com\/avatar\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Leonid Mamchenkov"},"datePublished":"2016-09-14T09:14:14+02:00","dateModified":"2016-09-14T09:14:14+02:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#webpage"},"isPartOf":{"@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#webpage"},"articleSection":"All, Programming, Technology, Web work, databases, MySQL, PHP, Unicode, web development"},{"@type":"BreadcrumbList","@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress#listItem","position":1,"name":"Home","item":"https:\/\/mamchenkov.net\/wordpress","nextItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/#listItem","position":2,"name":"Technology","item":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/#listItem","name":"Programming"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/#listItem","position":3,"name":"Programming","item":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/","nextItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#listItem","name":"MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;"},"previousItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/#listItem","name":"Technology"}},{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#listItem","position":4,"name":"MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;","previousItem":{"@type":"ListItem","@id":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/#listItem","name":"Programming"}}]},{"@type":"Person","@id":"https:\/\/mamchenkov.net\/wordpress\/#person","name":"Leonid Mamchenkov","image":{"@type":"ImageObject","@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#personImage","url":"https:\/\/secure.gravatar.com\/avatar\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Leonid Mamchenkov"}},{"@type":"Person","@id":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/#author","url":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/","name":"Leonid Mamchenkov","image":{"@type":"ImageObject","@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/3cf6df002a284d78fb6e9d8222ca4d102e0832035ed6bc8447008bd234e131a4?s=96&d=identicon&r=g","width":96,"height":96,"caption":"Leonid Mamchenkov"}},{"@type":"WebPage","@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#webpage","url":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/","name":"MySQL, PHP and \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d - Leonid Mamchenkov","description":"Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/mamchenkov.net\/wordpress\/#website"},"breadcrumb":{"@id":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/#breadcrumblist"},"author":{"@id":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/#author"},"creator":{"@id":"https:\/\/mamchenkov.net\/wordpress\/author\/leonid\/#author"},"datePublished":"2016-09-14T09:14:14+02:00","dateModified":"2016-09-14T09:14:14+02:00"},{"@type":"WebSite","@id":"https:\/\/mamchenkov.net\/wordpress\/#website","url":"https:\/\/mamchenkov.net\/wordpress\/","name":"Blog of Leonid Mamchenkov","description":"Life, universe, and everything else","inLanguage":"en-US","publisher":{"@id":"https:\/\/mamchenkov.net\/wordpress\/#person"}}]},"og:locale":"en_US","og:site_name":"Leonid Mamchenkov - Life, universe, and everything else","og:type":"article","og:title":"MySQL, PHP and \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d - Leonid Mamchenkov","og:description":"Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the","og:url":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/","og:image":"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg","og:image:secure_url":"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg","og:image:width":1024,"og:image:height":1024,"article:published_time":"2016-09-14T07:14:14+00:00","article:modified_time":"2016-09-14T07:14:14+00:00","article:publisher":"https:\/\/www.facebook.com\/MamchenkovBlog","twitter:card":"summary_large_image","twitter:site":"@mamchenkov","twitter:title":"MySQL, PHP and \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d - Leonid Mamchenkov","twitter:description":"Anna Filina blogs about an interesting problem she encountered with when working on a PHP and MySQL project: MySQL was complaining about \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the","twitter:creator":"@mamchenkov","twitter:image":"https:\/\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2026\/03\/leonid-sailing-beer.jpg"},"aioseo_meta_data":{"post_id":"26687","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2023-07-20 04:04:53","updated":"2026-01-15 12:22:46","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/mamchenkov.net\/wordpress\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/\" title=\"Technology\">Technology<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/\" title=\"Programming\">Programming<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tMySQL, PHP and \u201cIntegrity constraint violation: 1062 Duplicate entry\u201d\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/mamchenkov.net\/wordpress"},{"label":"Technology","link":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/"},{"label":"Programming","link":"https:\/\/mamchenkov.net\/wordpress\/category\/technology\/programming\/"},{"label":"MySQL, PHP and &#8220;Integrity constraint violation: 1062 Duplicate entry&#8221;","link":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/14\/mysql-php-and-integrity-constraint-violation-1062-duplicate-entry\/"}],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":12480,"url":"https:\/\/mamchenkov.net\/wordpress\/2010\/04\/21\/unit-tests-with-cakephp\/","url_meta":{"origin":26687,"position":0},"title":"Unit tests with CakePHP","author":"Leonid Mamchenkov","date":"April 21, 2010","format":false,"excerpt":"I've spent a large part of yesterday setting up the testing environment for a CakePHP project.\u00a0 As always, every time I do something that I have done before, I wanted to do it better, using all the experienced that was acquired previously.\u00a0 And this often leads to the discovery of\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26688,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/16\/bitbucket-pipelines-and-docker-for-php-developers\/","url_meta":{"origin":26687,"position":1},"title":"BitBucket Pipelines and Docker for PHP Developers","author":"Leonid Mamchenkov","date":"September 16, 2016","format":false,"excerpt":"I've been meaning to look into Docker for a long while now. \u00a0But, as always, time is the issue. \u00a0In the last couple of days though I've been integrating BitBucket Pipelines into our workflow. \u00a0BitBucket Pipelines is a continuous integration solution, which runs your project tests in a Docker container.\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27341,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/02\/12\/github-to-mysql\/","url_meta":{"origin":26687,"position":2},"title":"GitHub to MySQL","author":"Leonid Mamchenkov","date":"February 12, 2017","format":false,"excerpt":"GitHub to MySQL is a handy little app in PHP that pulls labels, milestones and issues from GitHub into your local MySQL database. \u00a0This is useful for analysis and backup purposes. There are a few example queries provided that show issues vs. pull requests,\u00a0average number of days to merge a\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2017\/02\/issues-vs-pull-requests-500x229.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":16547,"url":"https:\/\/mamchenkov.net\/wordpress\/2012\/07\/23\/economic-impact-of-open-source-on-small-business\/","url_meta":{"origin":26687,"position":3},"title":"Economic impact of open source on small business","author":"Leonid Mamchenkov","date":"July 23, 2012","format":"link","excerpt":"Economic impact of open source on small business Here are a few of the findings we derived from\u00a0Bluehost\u00a0data (an EIG company) and follow-on research: 60% of web hosting usage is by SMBs, 71% if you include non-profits. Only 22% of hosted sites are for personal use. WordPress is a far\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10151,"url":"https:\/\/mamchenkov.net\/wordpress\/2006\/05\/31\/daily-del-icio-us-bookmarks\/","url_meta":{"origin":26687,"position":4},"title":"Daily del.icio.us bookmarks","author":"Leonid Mamchenkov","date":"May 31, 2006","format":false,"excerpt":"Shared bookmarks for del.icio.us user tvset on 2006-05-30 MySQL Performance Blog \u00c2\u00bb INSERT ON DUPLICATE KEY UPDATE and summary counters. Tagged as: code databases mysql optimization performance programming sql tips tricks Read\/WriteWeb: Worldwide Internet Penetration is just 15% Tagged as: statistics stats web world","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9256,"url":"https:\/\/mamchenkov.net\/wordpress\/2005\/07\/21\/daily-del-icio-us-bookmarks\/","url_meta":{"origin":26687,"position":5},"title":"Daily del.icio.us bookmarks","author":"Leonid Mamchenkov","date":"July 21, 2005","format":false,"excerpt":"Shared bookmarks for del.icio.us user tvset on 2005-07-21 NewsForge | Hooking OOo to MySQL Tagged as: computers databases desktop mysql openoffice technology ALLCY.COM :: WELCOME :: -- All Cyprus: people and business finder and government pages Tagged as: cyprus government references search Writing Secure PHP - PHP - ILoveJackDaniels.com Tagged\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/26687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=26687"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/26687\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=26687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=26687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=26687"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=26687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}