-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Multiple data combined #502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Any plans to implement? Highly useful :) |
why not simply using array_merge($array1, $array2) right before calling insert? |
I guess, @premento means inserting several datasets at once into a database like: $data = [
['username1', $id1, 'password_hash1'],
['username2', $id2, 'password_hash2'],
];
$db->insert('users', $data); which is currently not supported. An |
yes, I was looking into this. Is there a sample to see how transactions could be used for the same? |
You can use transaction like described in the Readme. It should work with something like: $success = true;
$db->startTransaction();
foreach($data as $dataSet) {
if (!$db->insert ('tableName', $dataSet)) {
// something went wrong
$db->rollback();
$success = false;
break;
}
}
if ($success) {
$db->commit();
} |
If I'll find the time, I'll take a look at implementing a multi-dataSet insertion feature later today, if @avbdr has no problem with that. |
sure, go ahead. Ill glad to merge. We can call that method multiInsert or insertMulti(). We can optimize that later, but initial performance is not that bad when using transactions |
See merge request #504 |
fixed in master |
Just a doubt, instead of using 10 separate inserts, will there be any advantage in using this new multiInsert? Will the mysql write transactions reduce? |
if you are not doing all inserts in 1 transaction then most likely Richards work will be faster |
Is it possible to combine multiple arrays and insert in one INSERT statement? If so, how to do the combining of arrays?
The text was updated successfully, but these errors were encountered: