Executa um INSERT no banco
@param $table - Noma da Tabela
@param $data - Array com os dados do insert
@return string - id inserido no banco
171854
public function ExecuteInsert($table, $data)
    {
            if (is_object($data))
                ModelState::ModelTreatment($data);

            $data = (array)$data;

            // Ordena
            ksort($data);

            // Campos e valores
            $camposNomes = implode('`, `', array_keys($data));
            $camposValores = ':' . implode(', :', array_keys($data));

            // Prepara a Query
            $sth = $this->prepare("INSERT INTO $table (`$camposNomes`) VALUES ($camposValores)");

            // Define os dados
            foreach ($data as $key => $value) {
                // Se o tipo do dado for inteiro, usa PDO::PARAM_INT, caso contr�rio, PDO::PARAM_STR
                $tipo = (is_int($value)) ? PDO::PARAM_INT : PDO::PARAM_STR;

                // Define o dado
                $sth->bindValue(":$key", $value, $tipo);
            }

            // Executa
            $sth->execute();

            // Retorna o ID desse item inserido
            return $this->lastInsertId();
    }
318319
public function responseFilter($data, $table = '')
    {
        /* suka lupa ini object nya propel */
        if (is_object($data)) {
            $data = $data->toArray();
        }
        if ($table === '' && empty(static::DEFAULT_TABLE)) {
            return $data;
        } elseif ($table === '' && !empty(static::DEFAULT_TABLE)) {
            $table = static::DEFAULT_TABLE;
        }

        $excludeFields = Config::getConfig('excludeFields');
        if (!in_array($table, $excludeFields)) {
            return $data;
        } else {
            $tempData = $data;
            if (isset($tempData[0])) { // MULTIDIMENTIAL ARRAY
                foreach ($tempData as $k => $v) {
                    foreach ($v as $index => $value) {
                        if (is_array($value)) {
                            $tempData[$k][$index] = $this->responseFilter($value, $index);
                        } else {
                            foreach ($excludeFields[$table] as $exKey => $exVal) {
                                unset($tempData[$k][$exVal]);
                            }
                        }
                    }
                }
            } else { // SINGLE ARRAY
                foreach ($tempData as $index => $value) {
                    if (is_array($value)) {
                        $tempData[$k][$index] = $this->responseFilter($value, $index);
                    } else {
                        foreach ($excludeFields[$table] as $exKey => $exVal) {
                            unset($tempData[$k][$exVal]);
                        }
                    }
                }
            }
            return $tempData;
        }
    }
705437
public function updateOrInsert($table, array $data = [])
    {
        $primaryKeys = $this->repository->getCache()->getTablePrimaryKeys($table);

        if (strpos($table, '_i18n')) {
            $primaryKeys = ['id', 'language_id'];
        } elseif (strpos($table, '_p17n')) {
            $primaryKeys = ['id', 'user_group_id'];
        }

        /**
         * @T00D00 - bug for translations, permissions ...!
         */
        if (!$primaryKeys) {
            return;
        }

        foreach ($primaryKeys as $primaryKey) {
            if (!isset($data[$primaryKey])) {
                return;
            }
        }

        $entity = (new Entity($this->repository))->setTable($table);
        foreach ($primaryKeys as $primaryKey) {
            $entity->where($primaryKey, $data[$primaryKey]);
        }

        $entity->select(['`' . $table . '`.*']);
        $record = $entity->one();

        if ($record) {
            return $this->update($table, $data);
        }

        return (new InsertRecord($this->record, $this->entity, $this->repository))
            ->setTables($table)
            ->execute();
    }
453460
protected function buildInsertStatement($data) {
        $fields = '';
        $values = '';
        $first = true;
        foreach($data as $data_key => $data_val) {
            $fields .= ($first?'':',')."`$data_key`";
            $values .= ($first?'':',')."?";
            $first = false;
        }
        $table_name = $this->getTableName();
        return "INSERT INTO `{$table_name}` ({$fields}) VALUES ({$values})";
    }
906414
public function insert($table, array $data)
    {
        // Prepare
        $columnPart = "";
        $valuePart = "";

        // Loop the data
        foreach ($data as $column => $value) {
            $columnPart .= "`$column`, ";
            $valuePart .= "?, ";
        }

        // Remove last commas
        $columnPart = substr($columnPart, 0, -2);
        $valuePart = substr($valuePart, 0, -2);

        $query = "INSERT INTO `$table` ($columnPart) VALUES ($valuePart)";


        // Prepare and bind
        $statement = $this->prepare($query);

        $idx = 0;
        foreach ($data as $key => $value) {
            $statement->bindValue(($idx+1), $value, Database::typeOfValue($value));
            $idx++;
        }

        // Execute and return the execute returning value.
        return $statement->execute();
    }
448966
public function buildInsertQuery($table, $data)
    {
        $sql = "INSERT INTO " . $this->quoteSpecialName($table) . " ";

        if (!empty($data['ON DUPLICATE'])) {
            $onDuplicate = $data['ON DUPLICATE'];
            unset($data['ON DUPLICATE']);
        }

        $keys = $values = '';

        foreach ($data as $key => $value) {
            if (!empty($keys)) $keys .= ', ';
            if (!empty($values)) $values .= ', ';

            $keys .= '`' . $key . '`';
            $values .= $this->escapeItem($value);
        }

        $keys = '(' . $keys . ')';
        $values = '(' . $values . ')';

        $sql .= $keys . ' VALUES ' . $values;

        if (!empty($onDuplicate)) {
            $sql .= " ON DUPLICATE KEY UPDATE " . $onDuplicate;
        }

        $sql .= ';';

        return $sql;
    }
320636
public function insert_id($table = '')
    {
        if (!$this->db_connected || $this->db_mode == 'r') {
            return false;
        }

        if ($table) {
            // resolve table name
            $table = $this->table_name($table);
        }

        $id = $this->dbh->lastInsertId($table);

        return $id;
    }
715713
public function insert_or_update( $table, $data, $where ) {
		if ( ! isset( $this->table_defines[ $table ] ) ) {
			return false;
		}

		if ( $this->is_logical( $this->table_defines[ $table ] ) ) {
			$where['deleted_at'] = null;
		}

		$row = $this->select_row( $table, $where, 'id' );
		if ( empty( $row ) ) {
			$this->insert( $table, $data );
			if ( $this->get_last_error() ) {
				return false;
			}

			return $this->get_insert_id();
		}
		$where = [ 'id' => $row['id'] ];
		$this->update( $table, $data, $where );
		if ( $this->get_last_error() ) {
			return false;
		}

		return $row['id'];
	}
1310166
public function insert($table, array $data, $ignore = false)
    {
        $this->queryBuilder->insert($table, $this->asData($data), $ignore);
        return $this;
    }
153798
public function insert($data = null): IResult
    {
        $builder = new InsertBuilder($this);
        $sql = $builder->build($data);
        return $this->execute($sql);
    }
607900
public function insertBatch(string $table, array $data=[]): array
	{
		$data = (array) $data;
		$firstRow = (array) current($data);

		// Values for insertion
		$vals = [];
		foreach($data as $group)
		{
			$vals = array_merge($vals, array_values($group));
		}
		$table = $this->quoteTable($table);
		$fields = array_keys($firstRow);

		$sql = "INSERT INTO {$table} ("
			. implode(',', $this->quoteIdent($fields))
			. ') VALUES ';

		// Create the placeholder groups
		$params = array_fill(0, count($fields), '?');
		$paramString = '(' . implode(',', $params) . ')';
		$paramList = array_fill(0, count($data), $paramString);

		// Append the placeholder groups to the query
		$sql .= implode(',', $paramList);

		return [$sql, $vals];
	}
763957
function insert($data)
    {
        $field = "";
        $values = "";

        foreach($data as $key => $value)
        {
            $value = $this->db->quote($value);
            $field = $field . "`$key`,";
            $values = $values . "'$value',";
        }

        $field = substr($field, 0, -1);
        $values = substr($values, 0, -1);
        return $this->db->query("insert into {$this->table} ($field) values($values)");
    }
580922
public function insertBatch($table, $data = [], $safeModeInsert = true)
    {

        // PDO transactions start
        $this->start();
        // 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[0] 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[0]));
                // handle safe mode. If it is set as false means user not using bind param in pdo
                if (!$safeModeInsert) {
                    // set pdo insert statement in class property
                    $this->sql = "INSERT INTO `$table` ($sFields) VALUES ";
                    foreach ($data as $key => $value) {
                        $this->sql .= '(' . "'" . implode("', '", array_values($value)) . "'" . '), ';
                    }
                    $this->sql = rtrim($this->sql, ', ');
                    // return this object
                    // return $this;
                    // pdo prepare statement
                    $this->STH = $this->prepare($this->sql);
                    // start try catch block
                    try {
                        // execute pdo statement
                        if ($this->STH->execute()) {
                            // store all last insert id in array
                            $this->allLastId[] = $this->lastInsertId();
                        } else {
                            self::error($this->STH->errorInfo());
                        }
                    } catch (\PDOException $e) {
                        // get pdo error and pass on error method
                        self::error($e->getMessage() . ': ' . __LINE__);
                        // PDO Rollback
                        $this->back();
                    }// end try catch block

                    // PDO Commit
                    $this->end();
                    // close pdo
                    $this->STH->closeCursor();
                    // return this object
                    return $this;
                }

                // end here safe mode
                // 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 property with array
                $this->data = $data;
                // set batch insert flag true
                $this->batch = true;
                // parse batch array data
                foreach ($data as $key => $value) {
                    // bind pdo param
                    $this->_bindPdoNameSpace($value);

                    try {
                        // execute pdo statement
                        if ($this->STH->execute()) {
                            // set class property with last insert id as array
                            $this->allLastId[] = $this->lastInsertId();
                        } else {
                            self::error($this->STH->errorInfo());
                            // on error PDO Rollback
                            $this->back();
                        }
                    } catch (\PDOException $e) {
                        // get pdo error and pass on error method
                        self::error($e->getMessage() . ': ' . __LINE__);
                        // on error PDO Rollback
                        $this->back();
                    }
                }
                // fine now PDO Commit
                $this->end();
                // close pdo
                $this->STH->closeCursor();
                // return this object
                return $this;
            } else {
                self::error('Data not in valid format..');
            }
        } else {
            self::error('Table name not found..');
        }
    }
331627
public static function create($table, $data, $option = false)
    {
        $db = self::Using(self::$using_dbo_id);
        return $db->create($table, $data, $option);
    }
102419
public function insert(string $table): Query\Insert
    {
        $query = new Query\Insert();
        $query->insert($table);
        return $query;
    }
1248355
protected static function makeMultipleInsert($table, $data)
    {
        $insert_values = array();

        foreach ($data as $d) {
            $insert_values = array_merge($insert_values, array_values($d));

            $count = count($d);
            $array = array_fill(0, $count, '?');

            $placeholder[] = '('.implode(',', $array).')';
        }

        $column = implode(',', array_keys($data[0]));
        $values = implode(',', $placeholder);

        $query  = "INSERT INTO {$table} ({$column}) VALUES {$values}";

        return [$query, $insert_values];
    }
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);
        }
    }