Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions MysqliDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,39 +774,47 @@ public function insert($tableName, $insertData)
*
* @return bool|array Boolean indicating the insertion failed (false), else return id-array ([int])
*/
public function insertMulti($tableName, array $multiInsertData, array $dataKeys = null)
public function insertMulti($tableName, $multiInsertData, $dataKeys = null)
{
// only auto-commit our inserts, if no transaction is currently running
$autoCommit = (isset($this->_transaction_in_progress) ? !$this->_transaction_in_progress : true);
$ids = array();

$options = [
'_queryOptions' => $this->_queryOptions,
'_nestJoin' => $this->_nestJoin,
'_forUpdate' => $this->_forUpdate,
'_lockInShareMode' => $this->_lockInShareMode
];

if($autoCommit) {
$this->startTransaction();
}

foreach ($multiInsertData as $insertData) {
if($dataKeys !== null) {
// apply column-names if given, else assume they're already given in the data
$insertData = array_combine($dataKeys, $insertData);
}

foreach ($options as $k => $v) {
$this->{$k} = $v;
}
$id = $this->insert($tableName, $insertData);
if(!$id) {
if($autoCommit) {
if(!$id ) {
if($autoCommit && !in_array('IGNORE', $options['_queryOptions'])) {
$this->rollback();
}
return false;
return $id;
}
$ids[] = $id;
}

}
if($autoCommit) {
$this->commit();
}

}
return $ids;
}

/**
* Replace method to add new row
*
Expand Down