From f3af8eaf5a241976a57f52425c8c00ae4bf1b8e8 Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Mon, 28 May 2018 23:53:12 +0300 Subject: [PATCH] Rough fix #15 (handle null values) --- helpers/MysqlBackup.php | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/helpers/MysqlBackup.php b/helpers/MysqlBackup.php index 6d21ac8..749df31 100644 --- a/helpers/MysqlBackup.php +++ b/helpers/MysqlBackup.php @@ -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)