Insert using mysql REPLACE INTO.

@param array $data

@return int 1 if row is inserted without replacements, greater than 1 if rows were replaced
505514
public static function replace(array $data)
    {
        if (empty($data)) {
            return false;
        }

        // Case where $data is not an array of arrays.
        if (!isset($data[0])) {
            $data = [$data];
        }

        $sql = static::buildReplaceSql($data);

        $data = static::inLineArray($data);

        return self::getModelConnectionName()->affectingStatement($sql, $data);
    }
130656
protected function _insert(array $data)
    {
        $data = $this->_setData($data);
        $sql = Sql::createSql($this->getAdapter())->insert($this->getTableName());
        $event = new Save([
            'action' => Save::INSERT,
            'data' => $data,
            'abort' => false
        ]);
        $this->getEventManager()->trigger(Save::BEFORE_SAVE, $this, $event);
        if ($event->abort) {
            return false;
        }
        $result = $sql->set($event->data)->execute();

        if ($result > 0) {
            $pmk = $this->getPrimaryKey();
            $this->$pmk = $this->getAdapter()->getLastInsertId();
            $this->getEventManager()->trigger(Save::AFTER_SAVE, $this, $event);
        }
        return $result > 0;
    }
108174
public function row(array $data): int
    {
        array_push($this->rows, $data);
        $pdoStatement = $this->provideStatement();
        $this->execute($pdoStatement);
        return $this->getLastInsertId();
    }
513882
public function insert($table, array $data)
     {
         try {
             krsort($data);

             $fieldNme = implode('`,`', array_keys($data));
             $fieldValues = ':'.implode(',:', array_keys($data));
             $this->_beginTransaction();

             $stmt = $this->conn->prepare("INSERT INTO $table (`$fieldNme`) VALUES ($fieldValues)");

             foreach ($data as $key => $values) {
                 $stmt->bindValue(":$key", $values);
             }
             $this->_commit();
             $stmt->execute();
             unset($stmt);
         } catch (Exception $e) {
             $this->_Rollback();
             echo 'error insert '.$e->getMessage();
         }
     }
393916
public function insertOrUpdate($tableName, array $data)
    {
        $this->executeQuery("SET SESSION sql_mode='ALLOW_INVALID_DATES'", []);

        $columns = array_map(
            array($this, 'getQuotedName'),
            array_keys($data)
        );
        $updateAssignments = $this->getAssignmentsFor($data);
        return sprintf(
            "INSERT INTO %s (%s) VALUES (%s) ON DUPLICATE KEY UPDATE %s",
            $this->getQuotedName($tableName),
            implode(', ', $columns),
            implode(', ', array_fill(0, count($data), '?')),
            $updateAssignments
        );
    }
703063
public function insert(array $data) {
        $statement = new InsertStatement($data);
        $statement->setStatementContext($this->statementContext);
        $sql = $statement->parse();

        $result = $this->connection->execute($sql, $this->statementContext->getParameters());

        $this->clear();

        if ($result === false) {
            return false;
        }

        return $this->connection->lastInsertId();
    }
1199415
public function replace(array $data) {
        $addFields = implode('`,`', array_keys($data));
        return $this->command()
            ->insertOrReplace("`{$addFields}`", Str::repeat('?', $data),
                array_values($data));
    }
677039
protected static function inserts_processing ($data, $insert) {
		if (static::is_array_indexed($insert) && is_array($insert[0])) {
			$new_data = [];
			foreach ($insert as $i) {
				$new_data[] = static::inserts_replacing_recursive($data, $i);
			}
			return $new_data;
		}
		return static::inserts_replacing_recursive($data, $insert);
	}
917640
public function insertData($data)
    {
        $sql = $this->getInsertSql($data);
        try {
            $result = app("db")->insert($sql);
        } catch (\Exception $e) {
            Log::info('c=CopydataApiController f=insertData  msg=' . $e->getMessage());
            return false;
        }
        return $result;

    }
865927
public function add(array $data): Insert
    {
        if (!isset($data[0]) && count($this->fields) == 0) {
            $this->fields(array_keys($data));
        }

        $this->data[] = $data;
        return $this;
    }
1208998
public function haveInDatabase($table, array $data)
    {
        $lastInsertId = $this->_insertInDatabase($table, $data);

        $this->addInsertedRow($table, $data, $lastInsertId);

        return $lastInsertId;
    }
433240
private function insertData($data)
    {
        $inserted = Yii::$app->db->createCommand()->batchInsert(
            $this->getName(),
            $this->cleanUpBatchInsertFields($this->getFields()),
            $this->cleanUpMatchRow($data)
        )->execute();

        return $inserted;
    }
690562
public function insertRow(array $data, $position = 0, $insertType = self::INSERT_NODE)
    {
        $num = $this->fetchAll()->count();

        if ($num && $position) {
            $row = $this->getPosition($position);
            $lft_rgt = ($insertType === self::INSERT_NODE) ? $row->getRgt() : $row->getLft();
        } else {
            $lft_rgt = 0;
        }

        $this->updateTree($lft_rgt, '+', 2);

        $data[self::COLUMN_LEFT] = $lft_rgt + 1;
        $data[self::COLUMN_RIGHT] = $lft_rgt + 2;

        $insertId = parent::insert($data);

        return $insertId;
    }
153798
public function insert($data = null): IResult
    {
        $builder = new InsertBuilder($this);
        $sql = $builder->build($data);
        return $this->execute($sql);
    }
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();
    }
136525
protected static function buildReplaceSql(array $data)
    {
        $first = static::getFirstRow($data);

        $sql  = 'REPLACE INTO `' . static::getTablePrefix() . static::getTableName() . '`(' . static::getColumnList($first) . ') VALUES' . PHP_EOL;
        $sql .=  static::buildQuestionMarks($data);

        return $sql;
    }
1202213
public function insert(array $data) {
		$data = $this->filterFields($data, $this->_allowed_insert_fields);
		$data['created_at'] = Factory::load('\datetime')->format('Y-m-d H:i:s');

		return $this->_db->insertSafe($this->_table, $data);
	}