Yes, Big_Data is a good idea to insert a large number. But as AD7six notes, it still uses basic quoting of values ββand does not return insert identifiers. And based on your ideas, I wrote a small script to insert a large number into a single request, using CakePHP by default and returning the IDs of the inserted records.
$count = count($records); $dbSource = $this->getDataSource(); $table = $dbSource->fullTableName($this->table); $fields = $dbSource->prepareFields($this, array('fields' => array_keys($records[0]))); $values = array(); foreach ($records as $index => $record) { if (!is_array($record) || !$record) { return null; } foreach ($record as $column => $value) { $values[$index][$column] = $dbSource->value($value, $this->getColumnType($column)); } $values[$index] = '(' . implode(',', $values[$index]) . ')'; } $query = 'INSERT INTO %s (%s) VALUES %s;'; $query = sprintf($query, $table, implode(',', $fields), implode(',', $values)); if (!$dbSource->execute($query)) { return false; } $lastInsertId = $dbSource->getConnection()->lastInsertId(); $insertIds = array(); for ($i = 0; $i < $count; $i++) { $insertIds[] = $lastInsertId + $i; } return $insertIds;
source share