A
A
Alexander Shapoval2016-08-21 10:28:09
linux
Alexander Shapoval, 2016-08-21 10:28:09

Duplicate compound key error in MySQL. How to ignore these situations?

I created a clean project and added 'illuminate/database' to it to avoid writing sql code. The table has a composite key: field1 and field2. When adding an existing entry, an error appears:
Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry...
If an error occurs, the script stops its execution. How can I skip this error and continue working?
You can check before adding, but with large volumes - this is not good.
To add an entry, I use
Capsule::table('single')->insert($array);
Thank you for your help.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
Сайпутдин Омаров, 2016-05-22
@generalx

слишком много риторики! Логи где от виртуалбокса?

S
SagePtr, 2016-05-22
@SagePtr

В свойствах виртуальной машины PAE включён?

A
Alexander Shapoval, 2016-08-21
@AlexanderShapoval

Here is how I solved this problem:

Capsule::table('single')->updateOrInsert($array, $array);

O
Optimus, 2016-08-21
Pyan @marrk2

INSERT IGNORE

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question