public static function prepareMultiInsertOrUpdate(string $table, array $rows, array $ignoreForUpdate = []): array
    {
        $columns = static::extractColumnsFromRows($rows);
        $columns = static::escapeSqlWords($columns);
        $ignoreForUpdate = static::escapeSqlWords($ignoreForUpdate);

        /**
         * since PHP 7.1 this can look like:
         * ['params' => $params, 'valueParts' => $valueParts] = static::generateMultiParams($rows, $columns)
         */
        [$params, $valueParts] = array_values(static::generateMultiParams($rows, $columns));

        $sql = 'INSERT INTO ' . static::escapeSqlWords($table);
        $sql .= ' (' . implode(', ', $columns) . ')';
        $sql .= ' VALUES ';
        $sql .= implode(', ', $valueParts);
        $sql .= ' ON DUPLICATE KEY UPDATE ';

        $updateArray = [];
        foreach ($columns as $col) {
            if (! in_array($col, $ignoreForUpdate, true)) {
                $updateArray[] = "${col}=VALUES(${col})";
            }
        }
        $sql .= implode(', ', $updateArray);

        return [
            'sql' => $sql,
            'params' => $params,
        ];
    }
public static function prepareMultiInsertOrUpdate(string $table, array $rows, array $ignoreForUpdate = []): array
    {
        $columns = static::extractColumnsFromRows($rows);
        $columns = static::escapeSqlWords($columns);
        $ignoreForUpdate = static::escapeSqlWords($ignoreForUpdate);

        /**
         * since PHP 7.1 this can look like:
         * ['params' => $params, 'valueParts' => $valueParts] = static::generateMultiParams($rows, $columns)
         */
        [$params, $valueParts] = array_values(static::generateMultiParams($rows, $columns));

        $sql = 'INSERT INTO ' . static::escapeSqlWords($table);
        $sql .= ' (' . implode(', ', $columns) . ')';
        $sql .= ' VALUES ';
        $sql .= implode(', ', $valueParts);
        $sql .= ' ON DUPLICATE KEY UPDATE ';

        $updateArray = [];
        foreach ($columns as $col) {
            if (! in_array($col, $ignoreForUpdate, true)) {
                $updateArray[] = "${col}=VALUES(${col})";
            }
        }
        $sql .= implode(', ', $updateArray);

        return [
            'sql' => $sql,
            'params' => $params,
        ];
    }
public static function prepareMultiInsertOrUpdate ( string $ table , array $ rows , array $ ignoreForUpdate = [ ] ) : array { $ columns = static :: extractColumnsFromRows ( $ rows ) ; $ columns = static :: escapeSqlWords ( $ columns ) ; $ ignoreForUpdate = static :: escapeSqlWords ( $ ignoreForUpdate ) ; /**
         * since PHP 7.1 this can look like:
         * ['params' => $params, 'valueParts' => $valueParts] = static::generateMultiParams($rows, $columns)
         */ [ $ params , $ valueParts ] = array_values ( static :: generateMultiParams ( $ rows , $ columns ) ) ; $ sql = 'INSERT INTO ' . static :: escapeSqlWords ( $ table ) ; $ sql .= ' (' . implode ( ', ' , $ columns ) . ')' ; $ sql .= ' VALUES ' ; $ sql .= implode ( ', ' , $ valueParts ) ; $ sql .= ' ON DUPLICATE KEY UPDATE ' ; $ updateArray = [ ] ; foreach ( $ columns as $ col ) { if ( ! in_array ( $ col , $ ignoreForUpdate , true ) ) { $ updateArray [ ] = "${col}=VALUES(${col})" ; } } $ sql .= implode ( ', ' , $ updateArray ) ; return [ 'sql' => $ sql , 'params' => $ params , ] ; }
prepares "INSERT...ON DUPLICATE KEY UPDATE" sql statement by multi array of values
to be used for bulk inserts

@param string $table           table name
@param array  $rows            2-dimensional array of values to insert
@param array  $ignoreForUpdate columns that should not be updated

@return array [sql, params] prepared SQL and params

@throws DBALManagerException when number of columns and values does not match
prepares INSERT ... ON DUPLICATE KEY UPDATE sql statement by multi array of values to be used for bulk inserts