Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
INSERT with multiple associative arrays is order-dependent and not key-dependent #238
When inserting multiple associative arrays, the order in which the keys are defined in the first array is what is used for mapping the rest of the values. It should be based on key instead. I ended up with malformed data because values were ending up in columns they didn't belong in.
Steps To Reproduce
Very trivial example below, but assume that you have this data being constructed based on several conditions wherein the key order is different in the separate branches.
Assuming you have a table named
<?php $people = [ [ 'first' => 'John', 'last' => 'Doe' ], [ 'last' => 'Example', 'first' => 'Susan', ] ]; $db->query('INSERT INTO people', $people);
Check the table and Susan's first and last names are swapped.
Should evaluate an insert statement like the following:
INSERT INTO people (first, last) VALUES ("John", "Doe") ("Susan", "Example")
Instead it evaluates like this:
INSERT INTO people (first, last) VALUES ("John", "Doe") ("Example", "Susan")
Use keys for associative array case as opposed to the order within the array.