src/Services/PDOs/Builders/Builder.php
protected function doUpdate(array $data)
    {
        if (empty($data)) {
            throw new InvalidArgumentException('Cannot update an empty record.');
        }

        $bindings = array_merge($this->bindings['join'], $this->bindings['where']);
        $settings = [];
        $values   = [];
        if (empty($bindings) || is_int(key($bindings))) { // Prevent PDO-Error: "Invalid parameter number: mixed named and positional parameters"
            // bindings not used or question mark placeholders used
            foreach ($data as $column => $value) {
                $settings[] = $this->quoteColumn($column) . ' = ?';
                $values[]   = $value;
            }
        }
        else {
            // named placeholders are used
            foreach ($data as $column => $value) {
                $key = $column;
                if (isset($bindings[$key])) {
                    $i = 0;
                    do {
                        $key = $column . '_' . (++$i);
                    } while (isset($bindings[$key]) || isset($data[$key]));
                }
                $settings[] = $this->quoteColumn($column) . ' = :' . $key;
                $values[$key] = $value;
            }
        }

        $from     = ' ' . implode(', ', $this->from);
        $bindings = array_merge($this->bindings['join'], $values, $this->bindings['where']);
        $settings = ' SET ' . implode(', ', $settings);

        $query = 'UPDATE'
            . $from
            . $this->buildJoin()
            . $settings
            . $this->buildWhere();

        return $this->db->exec($query, $bindings);
    }
protected function doUpdate(array $data)
    {
        if (empty($data)) {
            throw new InvalidArgumentException('Cannot update an empty record.');
        }

        $bindings = array_merge($this->bindings['join'], $this->bindings['where']);
        $settings = [];
        $values   = [];
        if (empty($bindings) || is_int(key($bindings))) { // Prevent PDO-Error: "Invalid parameter number: mixed named and positional parameters"
            // bindings not used or question mark placeholders used
            foreach ($data as $column => $value) {
                $settings[] = $this->quoteColumn($column) . ' = ?';
                $values[]   = $value;
            }
        }
        else {
            // named placeholders are used
            foreach ($data as $column => $value) {
                $key = $column;
                if (isset($bindings[$key])) {
                    $i = 0;
                    do {
                        $key = $column . '_' . (++$i);
                    } while (isset($bindings[$key]) || isset($data[$key]));
                }
                $settings[] = $this->quoteColumn($column) . ' = :' . $key;
                $values[$key] = $value;
            }
        }

        $from     = ' ' . implode(', ', $this->from);
        $bindings = array_merge($this->bindings['join'], $values, $this->bindings['where']);
        $settings = ' SET ' . implode(', ', $settings);

        $query = 'UPDATE'
            . $from
            . $this->buildJoin()
            . $settings
            . $this->buildWhere();

        return $this->db->exec($query, $bindings);
    }
protected function doUpdate ( array $ data ) { if ( empty ( $ data ) ) { throw new InvalidArgumentException ( 'Cannot update an empty record.' ) ; } $ bindings = array_merge ( $ this -> bindings [ 'join' ] , $ this -> bindings [ 'where' ] ) ; $ settings = [ ] ; $ values = [ ] ; if ( empty ( $ bindings ) || is_int ( key ( $ bindings ) ) ) { // Prevent PDO-Error: "Invalid parameter number: mixed named and positional parameters" // bindings not used or question mark placeholders used foreach ( $ data as $ column => $ value ) { $ settings [ ] = $ this -> quoteColumn ( $ column ) . ' = ?' ; $ values [ ] = $ value ; } } else { // named placeholders are used foreach ( $ data as $ column => $ value ) { $ key = $ column ; if ( isset ( $ bindings [ $ key ] ) ) { $ i = 0 ; do { $ key = $ column . '_' . ( ++ $ i ) ; } while ( isset ( $ bindings [ $ key ] ) || isset ( $ data [ $ key ] ) ) ; } $ settings [ ] = $ this -> quoteColumn ( $ column ) . ' = :' . $ key ; $ values [ $ key ] = $ value ; } } $ from = ' ' . implode ( ', ' , $ this -> from ) ; $ bindings = array_merge ( $ this -> bindings [ 'join' ] , $ values , $ this -> bindings [ 'where' ] ) ; $ settings = ' SET ' . implode ( ', ' , $ settings ) ; $ query = 'UPDATE' . $ from . $ this -> buildJoin ( ) . $ settings . $ this -> buildWhere ( ) ; return $ this -> db -> exec ( $ query , $ bindings ) ; }
Update all records of the query result with th given data and return the number of affected rows.

@param array $data Values to be updated
@return int
Update all records of the query result with th given data and return the number of affected rows .