Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2011
    Posts
    4
    Plugin Contributions
    0

    Default 1062 Duplicate entry '261228-7443 'for key' PRIMARY '

    Hi I'm working as an import on db Zen Cart and a procedure fails me quite often so I tried to do this:
    try {
    $ result = $ db-> Execute ($ query);
    echo "Data successfully inserted. Insert ID:". $ VALUE_products_id;
    } Catch (Exception $ e) {
    echo $ e-> getMessage ();
    }

    But it does not work and the error:
    1062 Duplicate entry '261228-7443 'for key' PRIMARY '
    in:
    [INSERT INTO products ...
    still comes out as the fact is that stops me throughout the procedure. I would skip this thing what can I do?

  2. #2
    Join Date
    May 2013
    Posts
    38
    Plugin Contributions
    0

    Default Re: zen-cart try catch exception

    MySQL is telling you that you're trying to insert a Primary Key that already exists in the table. Primary Keys must be unique [1] and there can never be a duplicate.

    What data are you trying to insert into what table and why?

    [1] Unique key

  3. #3
    Join Date
    Jun 2011
    Posts
    4
    Plugin Contributions
    0

    Default Re: zen-cart try catch exception

    Quote Originally Posted by allthingsidLeroy View Post
    MySQL is telling you that you're trying to insert a Primary Key that already exists in the table. Primary Keys must be unique [1] and there can never be a duplicate.

    What data are you trying to insert into what table and why?

    [1] Unique key
    I know that a primary key can not be duplicated, but when you import large files to an external customer with automatic procedures at night it can happen that the file that you're importing is therefore wrong to have such lines dupicate. This is a mistake, however, to ensure that the import procedure is solid should not interrupt the process but only report the error otherwise the shop the next morning will no catagories and or products for example.

  4. #4
    Join Date
    May 2013
    Posts
    38
    Plugin Contributions
    0

    Default Re: zen-cart try catch exception

    Quote Originally Posted by crb_style View Post
    . . . should not interrupt the process but only report the error otherwise the shop the next morning will no catagories and or products for example.
    If you're running a query that contains an error, MySQL will generally interrupt the query, but the data inserted before the error should still be inserted. From the command-line, you can pass an argument (--force) which will force MySQL to keep going after errors. You might want to look at PHP's documentation to see how to pass this argument.

    This information says that mysql_query (which I think Zen Cart uses) doesn't throw exceptions, but returns false. So, if you still want the php script to continue running after an error -- because you presumably had more queries -- then you'd have to check for false values.

 

 

Similar Threads

  1. v151 PHP Fatal error:1062:Duplicate entry '1-1' for key 'PRIMARY'
    By Dopefish in forum General Questions
    Replies: 14
    Last Post: 19 Oct 2012, 02:58 AM
  2. Replies: 2
    Last Post: 26 Apr 2012, 11:48 PM
  3. 1062 Duplicate entry '31' for key 'PRIMARY'
    By yisou in forum General Questions
    Replies: 1
    Last Post: 8 Apr 2012, 05:18 PM
  4. 1062 Duplicate entry '5754' for key 'PRIMARY'
    By Pike Promo in forum General Questions
    Replies: 5
    Last Post: 17 Nov 2011, 04:52 AM
  5. Replies: 1
    Last Post: 24 Feb 2011, 05:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg