3

I'm looking for a "INSERT IGNORE INTO" option with Magento. I've created a custom table, and this table is updated every time an order is successfull (this is working). However, I want it only to insert in there if it is not existing yet on all 3 values.

My table

| customer_id (int) | customer_type (enum) | product_id (int) | id

customer_id registers the customers user id OR the session id if the customer is not logged in customer_type register if it's logged or session product_id registers the id the of the product id is the row identifier

On the succes page all these options are run through and added to my table. However if there is allready a row with all 3 exact matching it doesn't need to add it in there.

Anyone has a clue how to handle this?

1 Answer 1

4

You could create a unique constraint which covers all three fields, so an Insert would not create a new entry.

https://stackoverflow.com/questions/635937/how-do-i-specify-unique-constraint-for-multiple-columns-in-mysql

1
  • +1, constraint is a valid approach here as Zend_Db doesn't support INSERT IGNORE. Typical approach is to try/catch the exception raised on insert.
    – philwinkle
    Commented Feb 25, 2014 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.