diff --git a/src/Mysqldump.php b/src/Mysqldump.php index c6aa8cf..a2999f5 100644 --- a/src/Mysqldump.php +++ b/src/Mysqldump.php @@ -835,6 +835,7 @@ private function listValues(string $tableName) $ignore = $this->settings->isEnabled('insert-ignore') ? ' IGNORE' : ''; $count = 0; + $line = ''; foreach ($resultSet as $row) { $count++; $values = $this->prepareColumnValues($tableName, $row); @@ -842,34 +843,33 @@ private function listValues(string $tableName) if ($onlyOnce || !$this->settings->isEnabled('extended-insert')) { if ($this->settings->isEnabled('complete-insert') && count($colNames)) { - $lineSize += $this->write(sprintf( + $line .= sprintf( 'INSERT%s INTO `%s` (%s) VALUES (%s)', $ignore, $tableName, implode(', ', $colNames), $valueList - )); - } else { - $lineSize += $this->write( - sprintf('INSERT%s INTO `%s` VALUES (%s)', $ignore, $tableName, $valueList) ); + } else { + $line .= sprintf('INSERT%s INTO `%s` VALUES (%s)', $ignore, $tableName, $valueList); } $onlyOnce = false; } else { - $lineSize += $this->write(sprintf(',(%s)', $valueList)); + $line .= sprintf(',(%s)', $valueList); } - if (($lineSize > $this->settings->getNetBufferLength()) + if ((strlen($line) > $this->settings->getNetBufferLength()) || !$this->settings->isEnabled('extended-insert')) { $onlyOnce = true; - $lineSize = $this->write(';' . PHP_EOL); + $this->write($line . ';' . PHP_EOL); + $line = ''; } } $resultSet->closeCursor(); - if (!$onlyOnce) { - $this->write(';' . PHP_EOL); + if ($line !== '') { + $this->write($line. ';' . PHP_EOL); } $this->endListValues($tableName, $count);