public function insertOrUpdate(
        string $table,
        array $values,
        int $updateIgnoreCount = 1,
        ?array $excludeEmptyColumns = null
    ) {
        if (null !== $excludeEmptyColumns) {
            $values = SqlPreparator::setNullValues($values, $excludeEmptyColumns);
        }

        if ($updateIgnoreCount) {
            $ignoreForUpdate = array_slice(array_keys($values), 0, $updateIgnoreCount);
        } else {
            $ignoreForUpdate = [];
        }

        [$sql, $params] = array_values(SqlPreparator::prepareInsertOrUpdate($table, $values, $ignoreForUpdate));

        $this->lastStatement = $this->conn->executeUpdate($sql, $params);

        return $this->getLastInsertId();
    }
public function insertOrUpdate(
        string $table,
        array $values,
        int $updateIgnoreCount = 1,
        ?array $excludeEmptyColumns = null
    ) {
        if (null !== $excludeEmptyColumns) {
            $values = SqlPreparator::setNullValues($values, $excludeEmptyColumns);
        }

        if ($updateIgnoreCount) {
            $ignoreForUpdate = array_slice(array_keys($values), 0, $updateIgnoreCount);
        } else {
            $ignoreForUpdate = [];
        }

        [$sql, $params] = array_values(SqlPreparator::prepareInsertOrUpdate($table, $values, $ignoreForUpdate));

        $this->lastStatement = $this->conn->executeUpdate($sql, $params);

        return $this->getLastInsertId();
    }
public function insertOrUpdate ( string $ table , array $ values , int $ updateIgnoreCount = 1 , ? array $ excludeEmptyColumns = null ) { if ( null !== $ excludeEmptyColumns ) { $ values = SqlPreparator :: setNullValues ( $ values , $ excludeEmptyColumns ) ; } if ( $ updateIgnoreCount ) { $ ignoreForUpdate = array_slice ( array_keys ( $ values ) , 0 , $ updateIgnoreCount ) ; } else { $ ignoreForUpdate = [ ] ; } [ $ sql , $ params ] = array_values ( SqlPreparator :: prepareInsertOrUpdate ( $ table , $ values , $ ignoreForUpdate ) ) ; $ this -> lastStatement = $ this -> conn -> executeUpdate ( $ sql , $ params ) ; return $ this -> getLastInsertId ( ) ; }
executes "INSERT...ON DUPLICATE KEY UPDATE" sql statement by array of parameters

@param string     $table               table name
@param array      $values              values
@param int        $updateIgnoreCount   how many fields from beginning of array should be ignored on update
(i.e. indexes) default: 1 (the ID)
@param array|null $excludeEmptyColumns array of columns that can contain zero-equal values, set to null
if you want to disable auto-null entirely [default: null]

@return string|int InsertId

@see http://stackoverflow.com/questions/778534/mysql-on-duplicate-key-last-insert-id
executes INSERT ... ON DUPLICATE KEY UPDATE sql statement by array of parameters