concrete/src/Database/Connection/Connection.php
public function replace($table, $fieldArray, $keyCol, $autoQuote = true)
    {
        $qb = $this->createQueryBuilder();
        $qb->select('count(*)')->from($table, 't');
        $where = $qb->expr()->andX();
        $updateKeys = [];
        if (!is_array($keyCol)) {
            $keyCol = [$keyCol];
        }
        foreach ($keyCol as $key) {
            if (isset($fieldArray[$key])) {
                $field = $fieldArray[$key];
            } else {
                $field = null;
            }
            $updateKeys[$key] = $field;
            if ($autoQuote) {
                $field = $qb->expr()->literal($field);
            }
            $where->add($qb->expr()->eq($key, $field));
        }
        $qb->where($where);
        $sql = $qb->getSql();
        $num = parent::query($sql)->fetchColumn();
        if ($num) {
            $update = true;
        } else {
            try {
                $this->insert($table, $fieldArray);
                $update = false;
            } catch (UniqueConstraintViolationException $x) {
                $update = true;
            }
        }
        if ($update) {
            $this->update($table, $fieldArray, $updateKeys);
        }
    }
public function replace($table, $fieldArray, $keyCol, $autoQuote = true)
    {
        $qb = $this->createQueryBuilder();
        $qb->select('count(*)')->from($table, 't');
        $where = $qb->expr()->andX();
        $updateKeys = [];
        if (!is_array($keyCol)) {
            $keyCol = [$keyCol];
        }
        foreach ($keyCol as $key) {
            if (isset($fieldArray[$key])) {
                $field = $fieldArray[$key];
            } else {
                $field = null;
            }
            $updateKeys[$key] = $field;
            if ($autoQuote) {
                $field = $qb->expr()->literal($field);
            }
            $where->add($qb->expr()->eq($key, $field));
        }
        $qb->where($where);
        $sql = $qb->getSql();
        $num = parent::query($sql)->fetchColumn();
        if ($num) {
            $update = true;
        } else {
            try {
                $this->insert($table, $fieldArray);
                $update = false;
            } catch (UniqueConstraintViolationException $x) {
                $update = true;
            }
        }
        if ($update) {
            $this->update($table, $fieldArray, $updateKeys);
        }
    }
public function replace ( $ table , $ fieldArray , $ keyCol , $ autoQuote = true ) { $ qb = $ this -> createQueryBuilder ( ) ; $ qb -> select ( 'count(*)' ) -> from ( $ table , 't' ) ; $ where = $ qb -> expr ( ) -> andX ( ) ; $ updateKeys = [ ] ; if ( ! is_array ( $ keyCol ) ) { $ keyCol = [ $ keyCol ] ; } foreach ( $ keyCol as $ key ) { if ( isset ( $ fieldArray [ $ key ] ) ) { $ field = $ fieldArray [ $ key ] ; } else { $ field = null ; } $ updateKeys [ $ key ] = $ field ; if ( $ autoQuote ) { $ field = $ qb -> expr ( ) -> literal ( $ field ) ; } $ where -> add ( $ qb -> expr ( ) -> eq ( $ key , $ field ) ) ; } $ qb -> where ( $ where ) ; $ sql = $ qb -> getSql ( ) ; $ num = parent :: query ( $ sql ) -> fetchColumn ( ) ; if ( $ num ) { $ update = true ; } else { try { $ this -> insert ( $ table , $ fieldArray ) ; $ update = false ; } catch ( UniqueConstraintViolationException $ x ) { $ update = true ; } } if ( $ update ) { $ this -> update ( $ table , $ fieldArray , $ updateKeys ) ; } }
Insert or update a row in a database table.

@param string $table the name of the database table
@param array $fieldArray array keys are the field names, array values are the field values
@param string|string[] $keyCol the names of the primary key fields
@param bool $autoQuote set to true to quote the field values
Insert or update a row in a database table .