Magento – Using “INSERT IGNORE INTO” in MySQL

MySQLquery

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?

Best Answer

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

Related Topic