Skip to content

Commit

Permalink
Rough fix spanjeta#15 (handle null values)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickskrauch committed May 28, 2018
1 parent cead8b1 commit f3af8ea
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions helpers/MysqlBackup.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,24 @@ public function getData($tableName) {
$itemNames = array_keys ( $data );
$itemNames = array_map ( "addslashes", $itemNames );
$items = join ( '`,`', $itemNames );
$itemValues = array_values ( $data );
$itemValues = array_map ( "addslashes", $itemValues );
$valueString = join ( "','", $itemValues );
$valueString = "('" . $valueString . "'),";
$values = "\n" . $valueString;

if ($values != "") {
$data_string = "INSERT INTO `$tableName` (`$items`) VALUES" . rtrim ( $values, "," ) . ";;;" . PHP_EOL;
if ($this->fp)
fwrite ( $this->fp, $data_string );
}
$itemValues = array_values ( $data );
foreach ($itemValues as $i => $value) {
if ($value === null) {
$itemValues[$i] = 'NULL';
} else {
$itemValues[$i] = "'" . addslashes($value) . "'";
}
}

$valueString = implode(',', $itemValues );
$valueString = '(' . $valueString . '),';
$values = "\n" . $valueString;

if ($values != "") {
$data_string = "INSERT INTO `$tableName` (`$items`) VALUES" . $values . ";;;" . PHP_EOL;
if ($this->fp)
fwrite ( $this->fp, $data_string );
}
}

if ($this->fp)
Expand Down

0 comments on commit f3af8ea

Please sign in to comment.