We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

How to catch duplicate key error 1062

Development and Programming

AlteredState's avatar
AlteredState
57 posts
13 years ago
AlteredState's avatar AlteredState

Hi

Does anyone know how I would catch a duplicate key error 1062, thrown by MySQL?

I’m trying to import data into the EE database automatically, upon receipt from an external source, but I obviously don’t want to import the same data twice, hence I’m adding a unique key based on the data row to be inserted.

The 1062 error is thrown before testing with

if($this-EE->db-query($sql)) { ...

I’ve tried to catch the error by using

if (mysql_errno() == 1062) {...

and setting

$db['expressionengine']['db_debug'] = FALSE;

in config/database.php, but this has no effect. I’m still getting the error being thrown before anything else.

Does anyone know how to handle this?

Thanks in advance.

~ Steve

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.