public function update(array $data) : int
    {
        $table = $this->definition->getName();
        $columns = $this->definition->getFullColumns();
        $update = [];
        foreach ($data as $column => $value) {
            if (isset($columns[$column])) {
                $update[$column] = $this->normalizeValue($columns[$column], $value);
            }
        }
        if (!count($update)) {
            throw new DBException('No valid columns to update');
        }
        $sql = 'UPDATE '.$table.' SET ';
        $par = [];
        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
        $par = array_merge($par, array_values($update));
        if (count($this->where)) {
            $sql .= 'WHERE ';
            $tmp = [];
            foreach ($this->where as $v) {
                $tmp[] = $v[0];
                $par = array_merge($par, $v[1]);
            }
            $sql .= implode(' AND ', $tmp) . ' ';
        }
        if (count($this->order)) {
            $sql .= $this->order[0];
            $par = array_merge($par, $this->order[1]);
        }
        return $this->db->query($sql, $par)->affected();
    }
public function update(array $data) : int
    {
        $table = $this->definition->getName();
        $columns = $this->definition->getFullColumns();
        $update = [];
        foreach ($data as $column => $value) {
            if (isset($columns[$column])) {
                $update[$column] = $this->normalizeValue($columns[$column], $value);
            }
        }
        if (!count($update)) {
            throw new DBException('No valid columns to update');
        }
        $sql = 'UPDATE '.$table.' SET ';
        $par = [];
        $sql .= implode(', ', array_map(function ($v) { return $v . ' = ?'; }, array_keys($update))) . ' ';
        $par = array_merge($par, array_values($update));
        if (count($this->where)) {
            $sql .= 'WHERE ';
            $tmp = [];
            foreach ($this->where as $v) {
                $tmp[] = $v[0];
                $par = array_merge($par, $v[1]);
            }
            $sql .= implode(' AND ', $tmp) . ' ';
        }
        if (count($this->order)) {
            $sql .= $this->order[0];
            $par = array_merge($par, $this->order[1]);
        }
        return $this->db->query($sql, $par)->affected();
    }
public function update ( array $ data ) : int { $ table = $ this -> definition -> getName ( ) ; $ columns = $ this -> definition -> getFullColumns ( ) ; $ update = [ ] ; foreach ( $ data as $ column => $ value ) { if ( isset ( $ columns [ $ column ] ) ) { $ update [ $ column ] = $ this -> normalizeValue ( $ columns [ $ column ] , $ value ) ; } } if ( ! count ( $ update ) ) { throw new DBException ( 'No valid columns to update' ) ; } $ sql = 'UPDATE ' . $ table . ' SET ' ; $ par = [ ] ; $ sql .= implode ( ', ' , array_map ( function ( $ v ) { return $ v . ' = ?' ; } , array_keys ( $ update ) ) ) . ' ' ; $ par = array_merge ( $ par , array_values ( $ update ) ) ; if ( count ( $ this -> where ) ) { $ sql .= 'WHERE ' ; $ tmp = [ ] ; foreach ( $ this -> where as $ v ) { $ tmp [ ] = $ v [ 0 ] ; $ par = array_merge ( $ par , $ v [ 1 ] ) ; } $ sql .= implode ( ' AND ' , $ tmp ) . ' ' ; } if ( count ( $ this -> order ) ) { $ sql .= $ this -> order [ 0 ] ; $ par = array_merge ( $ par , $ this -> order [ 1 ] ) ; } return $ this -> db -> query ( $ sql , $ par ) -> affected ( ) ; }
Update the filtered rows with new data
@param  array  $data key value pairs, where each key is the column name and the value is the value to insert
@return int          the number of affected rows
Update the filtered rows with new data