public function batchInsert($table, array $data, $extra = null)
    {
        $table = $this->getTable($table);
        $field = implode(', ', array_keys($data[0]));
        $placeholders = array();
        $values = array();

        switch ($this->driver) {
            default:
            case 'mysql':
            case 'pgsql':
                foreach ($data as $row) {
                    $placeholders[] = '(' . implode(', ', array_pad(array(), count($row), '?')) . ')';
                    $values = array_merge($values, array_values($row));
                }
                $placeholder = 'VALUES ' . implode(', ', $placeholders);
                break;

            // For SQLite before 3.7.11, http://www.sqlite.org/releaselog/3_7_11.html
            case 'sqlite':
                foreach ($data as $row) {
                    $placeholders[] = 'SELECT ' . implode(', ', array_pad(array(), count($row), '?'));
                    $values = array_merge($values, array_values($row));
                }
                $placeholder = implode(' UNION ', $placeholders);
                break;
        }

        $query = "INSERT INTO $table ($field) $placeholder";
        $extra && $query .= ' ' . $extra;

        return $this->executeUpdate($query, $values);
    }
public function batchInsert($table, array $data, $extra = null)
    {
        $table = $this->getTable($table);
        $field = implode(', ', array_keys($data[0]));
        $placeholders = array();
        $values = array();

        switch ($this->driver) {
            default:
            case 'mysql':
            case 'pgsql':
                foreach ($data as $row) {
                    $placeholders[] = '(' . implode(', ', array_pad(array(), count($row), '?')) . ')';
                    $values = array_merge($values, array_values($row));
                }
                $placeholder = 'VALUES ' . implode(', ', $placeholders);
                break;

            // For SQLite before 3.7.11, http://www.sqlite.org/releaselog/3_7_11.html
            case 'sqlite':
                foreach ($data as $row) {
                    $placeholders[] = 'SELECT ' . implode(', ', array_pad(array(), count($row), '?'));
                    $values = array_merge($values, array_values($row));
                }
                $placeholder = implode(' UNION ', $placeholders);
                break;
        }

        $query = "INSERT INTO $table ($field) $placeholder";
        $extra && $query .= ' ' . $extra;

        return $this->executeUpdate($query, $values);
    }
public function batchInsert ( $ table , array $ data , $ extra = null ) { $ table = $ this -> getTable ( $ table ) ; $ field = implode ( ', ' , array_keys ( $ data [ 0 ] ) ) ; $ placeholders = array ( ) ; $ values = array ( ) ; switch ( $ this -> driver ) { default : case 'mysql' : case 'pgsql' : foreach ( $ data as $ row ) { $ placeholders [ ] = '(' . implode ( ', ' , array_pad ( array ( ) , count ( $ row ) , '?' ) ) . ')' ; $ values = array_merge ( $ values , array_values ( $ row ) ) ; } $ placeholder = 'VALUES ' . implode ( ', ' , $ placeholders ) ; break ; // For SQLite before 3.7.11, http://www.sqlite.org/releaselog/3_7_11.html case 'sqlite' : foreach ( $ data as $ row ) { $ placeholders [ ] = 'SELECT ' . implode ( ', ' , array_pad ( array ( ) , count ( $ row ) , '?' ) ) ; $ values = array_merge ( $ values , array_values ( $ row ) ) ; } $ placeholder = implode ( ' UNION ' , $ placeholders ) ; break ; } $ query = "INSERT INTO $table ($field) $placeholder" ; $ extra && $ query .= ' ' . $ extra ; return $ this -> executeUpdate ( $ query , $ values ) ; }
Insert batch data into table

@param string $table The name of table
@param array $data A two-dimensional array
@param string $extra A extra string concat after sql, like "ON DUPLICATE KEY UPDATE ..."
@return int The number of inserted rows
Insert batch data into table