Inserts record in data array and returns new record ID.

@param Model  $m
@param array  $data
@param string $table

@return mixed
963847
public function insert(Model $m, $data)
    {
        if (!$this->mode) {
            $this->mode = 'w';
        } elseif ($this->mode == 'r') {
            throw new Exception(['Currently reading records, so writing is not possible.']);
        }

        if (!$this->handle) {
            $this->saveHeader($m);
        }

        $line = [];

        foreach ($this->header as $name) {
            $line[] = $data[$name];
        }

        $this->putLine($line);
    }
519178
public function insert($table, array $data, $prepare = true)
    {
        if ($prepare) {
            $data = $this->prepareInsert($table, $data);
        }

        if (empty($data)) {
            return '0';
        }

        $keys = array_keys($data);
        $fields = implode(',', $keys);
        $values = ':' . implode(',:', $keys);

        $this->run("INSERT INTO $table ($fields) VALUES ($values)", $data);
        return $this->pdo->lastInsertId();
    }
1191015
public function insert($table, $data)
    {
        $fieldNames = implode(',', array_keys($data));
        $fieldValues = ':'.implode(', :', array_keys($data));

        $query = "INSERT INTO $table ($fieldNames) VALUES($fieldValues)";
        $this->prepare($query);

        /**
         * Iterate through data then bind the values
         */
        foreach ($data as $key => $value) {
            $this->bind(":$key", $value);
        }

        try {
            $this->execute();

            return true;
        } catch (PDOException $e) {
            echo $e->errorInfo[2];

            return false;
        }
    }
143355
public function insert($table, $data = [])
    {
        // check if table name not empty
        if (!empty($table)) {
            // and array data not empty
            if (count($data) > 0 && is_array($data)) {
                // get array insert data in temp array
                $tmp = [];
                foreach ($data as $f => $v) {
                    $tmp[] = ":s_$f";
                }
                // make name space param for pdo insert statement
                $sNameSpaceParam = implode(',', $tmp);
                // unset temp var
                unset($tmp);
                // get insert fields name
                $sFields = implode(',', array_keys($data));
                // set pdo insert statement in class property
                $this->sql = "INSERT INTO `$table` ($sFields) VALUES ($sNameSpaceParam);";
                // pdo prepare statement
                $this->STH = $this->prepare($this->sql);
                // set class where property with array data
                $this->data = $data;
                // bind pdo param
                $this->_bindPdoNameSpace($data);
                // use try catch block to get pdo error
                try {
                    // execute pdo statement
                    if ($this->STH->execute()) {
                        // set class property with last insert id
                        $this->lastId = $this->lastInsertId();
                        // close pdo
                        $this->STH->closeCursor();
                        // return this object
                        return $this;
                    } else {
                        self::error($this->STH->errorInfo());
                    }
                } catch (\PDOException $e) {
                    // get pdo error and pass on error method
                    self::error($e->getMessage() . ': ' . __LINE__);
                }
            } else {
                self::error('Data not in valid format..');
            }
        } else {
            self::error('Table name not found..');
        }
    }
523212
private function _createFkData($data, $table)
    {
        $name = $table . ucfirst(Text::singular($data['table'])) . 'Fk';
        $structure = [
            'constraintType' => 'FOREIGN KEY',
            'constraintName' => $name,
            'columnName' => $data['from'],
            'referenceTable' => $data['table'],
            'referenceColumn' => $data['to'],
            'onUpdate' => $data['on_update'],
            'onDelete' => $data['on_delete']
        ];
        return $structure;
    }
1301427
public function insert(array $data)
    {
        if (isset($data['id'])) {
            if (array_key_exists($data['id'], $this->table->data['data'])) {
                return null;
            }
        } else {
            $data = ['id' => $this->generateId()] + $data;
        }

        $this->table->data['data'][$data['id']] = $data;
        $this->table->save();

        return $data['id'];
    }
785077
public static function update($table, $data = null, $where = null) {
        if ($data) {
            Update::update($table, $data, $where);
            return null;
        } else {
            return Update::table($table);
        }
    }
961249
public function insert($table_name, array $data) {
            Event::dispatch(EventData::forBefore(Event::BEFORE_INSERT, $table_name, $data), $data);

            $q = $this->config->getSystemIdentifierQuote();
            $fields = [];
            $data_values = "";
            $statement_params = [];
            $null_params = [];

            foreach ($data as $field_name => $value) {
                $fields[] = "\n$q" . $field_name . $q;
                if (strtolower($value) == 'null' || is_null($value)) {
                    $data_values .= 'NULL,';
                    $null_params[ $field_name ] = 'NULL';
                } else {
                    $data_values .= ':' . $field_name . ',';
                    $statement_params[ ':' . $field_name ] = $value;
                }
            }

            $full_param_list = array_merge($statement_params, $null_params);

            $fields = implode(',', $fields);
            $data_values = substr($data_values, 0, -1);
            $sql_query = "INSERT INTO \n$q" . $table_name . "$q ( " . $fields . " )\n VALUES (" . $data_values . ")";
            if ($this->config->db_type === 'pgsql') {
                $sql_query .= "\nRETURNING id;\n";
            }

            try {
                $stmt = $this->db_connection->prepare($sql_query);
                if ($statement_params) {
                    foreach ($statement_params as $k => $v) {
                        $stmt->bindValue($k, $v);
                    }
                }
                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $sql_query, $full_param_list));
                throw new QueryException($ex->getMessage(), $ex->getCode(), $ex);
            }

            if ($this->config->db_type === 'pgsql') {
                $insert_id = $stmt->fetchColumn(0);
            } else {
                $insert_id = $this->db_connection->lastInsertId();
            }

            $rows_affected = empty($insert_id) ? 0 : 1;
            Event::dispatch(EventData::forAfter(Event::AFTER_INSERT, $table_name, $full_param_list, $sql_query, $rows_affected, $insert_id));

            return $insert_id;
        }
466184
public function addColumn($table, $name, $data)
    {

        $q = "ALTER TABLE {$table} ADD {$name}";
        $v = $data;

        if (isset($v['type'])) {
            $q .= " {$v['type']}";
            if (isset($v['length'])) {
                $q .= "({$v['length']})";
            } else {
                if ($v['type'] != 'int' && $v['type'] != 'datetime') {
                    die ("Please set length for table: {$name} - column: {$name}");
                }
            }

            if (isset($v['unsigned']) && $v['unsigned'] == true) {
                $q .= " UNSIGNED";
            }

            if (!isset($v['null']) || $v['null'] == false) {
                $q .= " NOT NULL";
            }

            if (isset($v['default'])) {
                if (is_string($v['default'])) {
                    $v['default'] = "'{$v['default']}'";
                }

                $q .= " DEFAULT {$v['default']}";
            }

            if (isset($v['ai']) && $v['ai'] == true) {
                $q .= " AUTO_INCREMENT";
            }

            if ((isset($v['unique']) && $v['unique'] == true) && (isset($v['primary']) && $v['primary'] == true)) {
                die ("Unique or Primary?");
            }

            if (isset($v['unique']) && $v['unique'] == true) {
                $q .= " UNIQUE";
            }

            if (isset($v['primary']) && $v['primary'] == true) {
                $q .= " PRIMARY KEY";
            }

            if (isset($v['after'])) {
                $q .= " AFTER {$v['after']}";
            }

        } else {
            die ("Please set type of column ");
        }

        return $this->executeQuery($q);
    }
287714
final protected function insert(string $table, array $data): AbstractMigration
    {
        $this->execute($this->adapter->buildInsertQuery($table, $data));
        return $this;
    }
351649
public function insert($table, array $data)
    {
        $nameFields = join(',', array_keys($data));
        $preparedValues = $this->prepareValues($data);
        $keyValues = join(",", array_keys($preparedValues));
        $queryString = "INSERT INTO {$table} ({$nameFields}) VALUES ({$keyValues});";

        $this->query($queryString, $preparedValues);

        return $this->getInsertId();
    }
60876
public static function insert($table, $data = array(), $config = array()) {
        DB::connect();
        return DB::$connection->insert($table, $data, $config);
    }
445935
public function insert($table, $data)
    {
        // empty data
        if (empty($data))
            Throw new \ErrorException("SQL Error: Can't insert empty data.");

        // prepare data
        $cols = ($values = array());
        foreach ($data as $column => $value) {
            $cols[] = '`' . $column . '`';
            $values[] = "'" . $this->escape($value) . "'";
        }

        // build query string...
        $query_string = 'INSERT INTO `' . $this->getPrefix() . $table . '` (' . implode(',', $cols) . ') VALUES (' . implode(',', $values) . ')';

        return $this->doQuery($query_string); // ... and execute
    }
575786
public function insert($tableName, array $data)
    {
        $query = sprintf("INSERT INTO $tableName (%s) VALUES (%s)",
            implode(', ', array_keys($data)), 
            implode(', ', array_fill(0, count($data), '?'))
        );

        $stmt = $this->prepare($query);
        $stmt->execute(array_values($data));
        return $stmt;
    }
627088
public function getQueryData($table, array $data)
    {
        $columns = $this->getSchemaManager()->listTableColumns($table);

        $allColumnTypes = $this->getColumnTypes($table);
        $columnTypes = [];
        foreach ($columns as $column) {
            $columnName = $column->getName();
            if (\array_key_exists($columnName, $data)) {
                $columnTypes[$this->connection->quoteIdentifier($columnName)] = $allColumnTypes[$columnName];
            }
        }

        $quotedData = [];
        foreach ($data as $column => $value) {
            $quotedColumn = $this->connection->quoteIdentifier($column);
            if (\array_key_exists($quotedColumn, $columnTypes)) {
                $quotedData[$quotedColumn] = $value;
            }
        }

        \ksort($quotedData);
        \ksort($columnTypes);

        return new QueryData(
            $this->connection->quoteIdentifier($table),
            $quotedData,
            \array_values($columnTypes)
        );
    }
9723
public static function insert($table, $data) {
        $insert = Insert::table($table);
        foreach ($data as $field => $value) {
            $insert->set($field, $value);
        }
        return $insert->excuse();
    }
1252436
public function save(string $table, array $data): array
    {
        try {
            $this->db->beginTransaction();

            $query = "INSERT INTO $table (" .
                implode(', ', array_keys($data)) .
                ") VALUES (" .
                substr(str_repeat(', ?', count($data)), 1) .
                ")" .
                " ON DUPLICATE KEY UPDATE " .
                implode('=?, ', array_keys($data)) . "=?";

            $duplicateDate = array_merge(array_values($data), array_values($data));
            /** @var PDOStatement $stmt */
            $stmt = $this->db->prepare(
                $query
            );
            $stmt->execute(array_values($duplicateDate));
            $this->db->commit();

            return $data;
        } catch (PDOException $e) {
            $this->db->rollBack();
            throw new PDOException($e);
        }
    }