diff --git a/phpBB/phpbb/db/driver/driver.php b/phpBB/phpbb/db/driver/driver.php index c924d4626a..6c86433dd9 100644 --- a/phpBB/phpbb/db/driver/driver.php +++ b/phpBB/phpbb/db/driver/driver.php @@ -724,38 +724,28 @@ abstract class driver implements driver_interface return false; } - if ($this->multi_insert) + $ary = array(); + foreach ($sql_ary as $_sql_ary) { - $ary = array(); - foreach ($sql_ary as $id => $_sql_ary) + // If by accident the sql array is only one-dimensional we build a normal insert statement + if (!is_array($_sql_ary)) { - // If by accident the sql array is only one-dimensional we build a normal insert statement - if (!is_array($_sql_ary)) - { - return $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $sql_ary)); - } + return $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $sql_ary)); + } + // Add values to set to $ary if multi insert is supported, otherwise run every insert query separately + if ($this->multi_insert) + { $values = array(); - foreach ($_sql_ary as $key => $var) + foreach ($_sql_ary as $var) { $values[] = $this->_sql_validate_value($var); } $ary[] = '(' . implode(', ', $values) . ')'; } - - return $this->sql_query('INSERT INTO ' . $table . ' ' . ' (' . implode(', ', array_keys($sql_ary[0])) . ') VALUES ' . implode(', ', $ary)); - } - else - { - foreach ($sql_ary as $ary) + else { - if (!is_array($ary)) - { - return false; - } - - $result = $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $ary)); - + $result = $this->sql_query('INSERT INTO ' . $table . ' ' . $this->sql_build_array('INSERT', $_sql_ary)); if (!$result) { return false; @@ -763,6 +753,11 @@ abstract class driver implements driver_interface } } + if ($this->multi_insert) + { + return $this->sql_query('INSERT INTO ' . $table . ' ' . ' (' . implode(', ', array_keys($sql_ary[0])) . ') VALUES ' . implode(', ', $ary)); + } + return true; }