Skip to content

Commit 20b47d7

Browse files
author
Alin Olteanu
committed
insertMulti ... ON DUPLICATE KEY UPDATE
1 parent 47644d0 commit 20b47d7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
"AlinO\\Db\\": "src"
3131
}
3232
},
33-
"version": "3.1.4"
33+
"version": "3.1.5"
3434
}

src/MysqliDb.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,12 +1001,21 @@ public function insertMulti($tableName, array $multiInsertData, array $dataKeys
10011001
$this->startTransaction();
10021002
}
10031003

1004+
$update = $this->_updateColumns;
1005+
unset($this->_updateColumns);
1006+
10041007
foreach ($multiInsertData as $insertData) {
10051008
if (!empty($dataKeys)) {
10061009
// apply column-names if given, else assume they're already given in the data
10071010
$insertData = array_combine($dataKeys, $insertData);
10081011
}
10091012

1013+
if (!empty($update)) {
1014+
foreach ($update as $key) {
1015+
$this->_updateColumns[$key] = $insertData[$key] ?? null;
1016+
}
1017+
}
1018+
10101019
$id = $this->insert($tableName, $insertData);
10111020
if (!$id) {
10121021
if ($autoCommit) {

0 commit comments

Comments
 (0)