Index: t3lib/class.t3lib_db.php =================================================================== --- t3lib/class.t3lib_db.php (revision 6748) +++ t3lib/class.t3lib_db.php (working copy) @@ -187,6 +187,23 @@ } /** + * Creates and executes an INSERT SQL-statement for $table with multiple rows. + * + * @param string Table name + * @param array Field names + * @param array Table rows. Each row should be an array with field values mapping to $fields + * @param string/array See fullQuoteArray() + * @return pointer MySQL result pointer / DBAL object + */ + public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) { + $res = mysql_query($this->INSERTmultipleRows($table, $fields, $rows, $no_quote_fields), $this->link); + if ($this->debugOutput) { + $this->debug('exec_INSERTmultipleRows'); + } + return $res; + } + + /** * Creates and executes an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values. * Using this function specifically allow us to handle BLOB and CLOB fields depending on DB * Usage count/core: 50 @@ -413,6 +430,41 @@ } /** + * Creates an INSERT SQL-statement for $table with multiple rows. + * + * @param string Table name + * @param array Field names + * @param array Table rows. Each row should be an array with field values mapping to $fields + * @param string/array See fullQuoteArray() + * @return string Full SQL query for INSERT (unless $rows does not contain any elements in which case it will be false) + */ + public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) { + // Table and fieldnames should be "SQL-injection-safe" when supplied to this + // function (contrary to values in the arrays which may be insecure). + if (count($rows)) { + // Build query: + $query = 'INSERT INTO ' . $table . + '(' . implode(',', $fields) . ') VALUES '; + + $rowSQL = array(); + foreach ($rows as $row) { + // quote and escape values + $row = $this->fullQuoteArray($row, $table, $no_quote_fields); + $rowSQL[] = '( ' . implode(',', $row) . ') '; + } + + $query .= implode(',', $rowSQL); + + // Return query: + if ($this->debugOutput || $this->store_lastBuiltQuery) { + $this->debug_lastBuiltQuery = $query; + } + + return $query; + } + } + + /** * Creates an UPDATE SQL-statement for $table where $where-clause (typ. 'uid=...') from the array with field/value pairs $fields_values. * Usage count/core: 6 *