Edit:
In case you didn’t notice the passed $aWorks array has numeric array keys whereas the aFailed array uses named keys.
I would have thought the passed data was the same. Is this a bug?
Well aWorks is definitely numeric: $aWorks[] = $tmp;
No key = next numeric key.
I… dont see where $aInserts is being defined though. $aFails is defined by: $aInserts as $id => $aFails
so $aFails will have the same structure as the elements of $aInserts.
If you wanted them to be identical, you’d make this line: $aWorks[] = $tmp;
into $aWorks[$id2] = $tmp;
(but at that point, why bother.)
Many thanks for the explanation - so simple when you know how
I will try tomorrow because it is now past my bedtime.
I dare not mention how long I was stuck with this problem. the most annoying thing was there was no errors returned only the following false return value which was not very informative:
Yeah, unfortunately there’s not a good way to pull down the query the database actually executed (a side-effect of prepared statements: You arent actually compiling a string at the PHP end, you’re sending the database the string and the parameters separately).
As always, if you get stuck with things, ask! The number of times everyone here has sat, staring at a piece of code and screaming “WHY DONT YOU WORK”… we’ve all been there. Fresh set of eyes is usually all that’s needed.
I did discover that when importing another CSV there was problems with missing unique reference field and also the columns were not in the same order. I was thinking of creating an additional unique reference column and having to use ALTER to change the other columns to suit the search routine until… i realised it was possible to add the reference field index and also insert the columns in a different order. This saved quite a bit of coding and validation
I assume from the above (and for clarity for any that might follow) that you’ve told your connection object to setAttribute for PDO::ERROR_EXCEPTION, as otherwise $ok will never throw anything.
(Default behavior: $ok becomes FALSE, throw no exception.)
As far as the return result $ok = $stmt->execute($tmp); it is a habit that was recommended by my C++ Tutor. If problems occur after calling the PHP function, I follow the statement with var_dump($ok);