diff --git a/src/D2Database.php b/src/D2Database.php index b228605..d09eccc 100644 --- a/src/D2Database.php +++ b/src/D2Database.php @@ -51,28 +51,28 @@ class D2Database { $sql = ''; if (!empty($data)) { foreach ($data as $d) { - $sql = "INSERT INTO `$tableName` ("; + if (!empty($d)) { + $sql = "INSERT INTO `$tableName` ("; foreach ($d as $k => $v) { $sql .= "`$k`" . ","; } + $sql = rtrim($sql, ","); + $sql .= ") "; } - $sql = rtrim($sql, ","); - $sql .= ") "; } } $sql .= "VALUES "; if (!empty($data)) { foreach ($data as $d) { - $sql .= "("; - if (!empty($d)) { + $sql .= "("; foreach ($d as $k => $v) { $sql .= '"' . $v . '"' . ","; } + $sql = rtrim($sql, ","); + $sql .= "), "; } - $sql = rtrim($sql, ","); - $sql .= "), "; } $sql = rtrim($sql, ", "); PDO_Execute($sql);