CI_DB_query_builder::insert_batch PHP Method

insert_batch() public method

Compiles batch insert strings and runs the queries
public insert_batch ( string $table, array $set = NULL, boolean $escape = NULL, $batch_size = 100 ) : integer
$table string Table to insert into
$set array An associative array of insert values
$escape boolean Whether to escape values and identifiers
return integer Number of rows inserted or FALSE on failure
    public function insert_batch($table, $set = NULL, $escape = NULL, $batch_size = 100)
    {
        if ($set === NULL) {
            if (empty($this->qb_set)) {
                return $this->db_debug ? $this->display_error('db_must_use_set') : FALSE;
            }
        } else {
            if (empty($set)) {
                return $this->db_debug ? $this->display_error('insert_batch() called with no data') : FALSE;
            }
            $this->set_insert_batch($set, '', $escape);
        }
        if (strlen($table) === 0) {
            if (!isset($this->qb_from[0])) {
                return $this->db_debug ? $this->display_error('db_must_set_table') : FALSE;
            }
            $table = $this->qb_from[0];
        }
        // Batch this baby
        $affected_rows = 0;
        for ($i = 0, $total = count($this->qb_set); $i < $total; $i += $batch_size) {
            $this->query($this->_insert_batch($this->protect_identifiers($table, TRUE, $escape, FALSE), $this->qb_keys, array_slice($this->qb_set, $i, $batch_size)));
            $affected_rows += $this->affected_rows();
        }
        $this->_reset_write();
        return $affected_rows;
    }