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 * Index: typo3/sysext/dbal/class.ux_t3lib_db.php =================================================================== --- typo3/sysext/dbal/class.ux_t3lib_db.php (revision 6748) +++ typo3/sysext/dbal/class.ux_t3lib_db.php (working copy) @@ -490,6 +490,28 @@ } /** + * Creates and executes an INSERT SQL-statement for $table with multiple rows. + * This method uses exec_INSERTquery() and is just a syntax wrapper to it. + * + * @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 mixed Result from last handler, usually TRUE when success and FALSE on failure + */ + public function exec_INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) { + foreach ($rows as $row) { + $fields_values = array(); + foreach ($fields as $key => $value) { + $fields_values[$value] = $row[$key]; + } + $res = $this->exec_INSERTquery($table, $fields_values, $no_quote_fields); + } + + return $res; + } + + /** * Updates a record from $table * * @param string Database tablename @@ -860,6 +882,35 @@ } /** + * Creates an INSERT SQL-statement for $table with multiple rows. + * This method will create multiple INSERT queries concatenated with ';' + * + * @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 array Full SQL query for INSERT as array of strings (unless $fields_values does not contain any elements in which case it will be FALSE). If BLOB fields will be affected and one is not running the native type, an array will be returned for each row, where 0 => plain SQL, 1 => fieldname/value pairs of BLOB fields. + */ + public function INSERTmultipleRows($table, array $fields, array $rows, $no_quote_fields = FALSE) { + $result = array(); + + foreach ($rows as $row) { + $fields_values = array(); + foreach ($fields as $key => $value) { + $fields_values[$value] = $row[$key]; + } + $rowQuery = $this->INSERTquery($table, $fields_values, $no_quote_fields); + if (is_string($rowQuery)) { + $result[][0] = $rowQuery; + } else { + $result[] = $rowQuery; + } + } + + return $result; + } + + /** * 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 *