Perform a UPDATE statement

@param string $table
@param array $data
@param string $conditions

@return int number of affected rows
166757
public function update($table, array $data, $conditions)
    {
        $nameFields = array_keys($data);
        $preparedValues = $this->prepareValues($data);
        $queryString = "UPDATE {$table} SET ";

        $fNumber = 0;
        foreach ($preparedValues as $key => $value) {
            unset($value);
            $queryString .= "{$nameFields[$fNumber]} = {$key}, ";
            $fNumber++;
        }

        $queryString = preg_replace('/,\ $/', ' ', $queryString);
        $queryString .= "WHERE {$conditions};";

        $this->query($queryString, $preparedValues);

        return $this->getAffectedRows();
    }
1050029
public function delete($table, array $conditions)
    {
        $table = $this->getTable($table);
        $where = $this->buildSqlObject($conditions, ' AND ');

        $query = "DELETE FROM $table WHERE " . $where;
        return $this->executeUpdate($query, array_values($conditions));
    }
382986
public function update($table, $data, $condition)
    {
        if ( empty($condition) ) return false;
        $_T_fields = $this->getTableFields($table);
        $_keys = '';
        foreach ( $data as $_key => $_val ) {

            //过滤不存在的字段
            if ( !in_array($_key, $_T_fields) ) continue;
            if ( is_null($_val) ) {
                $_val = 'NULL';
            } else {
                $_val = "'{$_val}'";
            }
            $_keys .= $_keys == ''? "`{$_key}`={$_val}" : ", `{$_key}`={$_val}";
        }
        if ( $_keys !== '' ) {
            $_query = "UPDATE {$table} SET " . $_keys . $condition;
            $result = $this->execute($_query);
            if ( $result != false ) {
                return $result->rowCount() > 0 ? $result->rowCount() : true;
            }
        }
        return false;
    }
822041
public function update($table, array $values = null)
    {
        $builder         = new Update($this->driver);
        $this->lastQuery = $builder;

        if ($values) {
            $builder->values($values);
        }

        return $builder->update($table);
    }
197807
public function update($table, $fieldValues, $conditions, $bind = [])
    {
        if (!$fieldValues) {
            throw new InvalidArgumentException(['Unable to update :table table without data', 'table' => $table]);
        }

        if (is_string($conditions)) {
            $conditions = [$conditions];
        }

        $wheres = [];

        /** @noinspection ForeachSourceInspection */
        foreach ($conditions as $k => $v) {
            if (is_int($k)) {
                $wheres[] = stripos($v, ' or ') ? "($v)" : $v;
            } else {
                $wheres[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $setFields = [];
        foreach ($fieldValues as $k => $v) {
            if (is_int($k)) {
                $setFields[] = $v;
            } elseif ($v instanceof AssignmentInterface) {
                $v->setFieldName($k);
                $setFields[] = $v->getSql();
                /** @noinspection SlowArrayOperationsInLoopInspection */
                $bind = array_merge($bind, $v->getBind());
            } else {
                $setFields[] = "[$k]=:$k";
                $bind[$k] = $v;
            }
        }

        $sql = 'UPDATE ' . $this->_escapeIdentifier($table) . ' SET ' . implode(',', $setFields) . ' WHERE ' . implode(' AND ', $wheres);

        return $this->_execute('update', $sql, $bind);
    }
719676
public function update($table, array $data, $where = [], array $bind = [])
    {
        $table  = $this->quote()->identifier($table);
        $fields = [];
        foreach ($data as $field => $value) {
            $fields[] = $this->quote()->into("{$field} = ?", $value);
        }
        $sql = "UPDATE $table SET " . implode(', ', $fields);
        if (is_array($where)) {
            $where = $this->createWhereExpression($where);
        }
        $sql .= (($where) ? " WHERE {$where}" : '');

        $stmt = $this->query($sql, $bind);

        return $stmt->rowCount();
    }
1126545
public function buildUpdateSQL($table = null, $data = array())
	{
		$sql = 'update ' . $this->parseTable($table) . ' set ';
		if(is_string($data))
		{
			$sql .= $data . ' ';
		}
		else
		{
			$data = $this->parseParams($data);
			foreach($data as $key => $value)
			{
				$sql .= $this->parseKeyword($key) . '=:' . $this->parseParamName($key) . ',';
			}
		}
		$where = $this->parseCondition(isset($this->operationOption['where']) ? $this->operationOption['where'] : '');
		if ('' !== $where)
		{
			$where = 'where ' . $where . ' ';
		}
		return substr($sql,0,-1) . ' '
				. $where
				. $this->parseOrder()
				. $this->parseLimit()
				. $this->parseLock()
				;
	}
1006801
public function update($table, $data, $where = '')
    {
        $fieldDetails = null;
        foreach ($data as $key => $value) {
            $fieldDetails .= "$key = :$key,";
        }
        $fieldDetails = rtrim($fieldDetails, ',');
        $query = "UPDATE $table SET $fieldDetails ".($where ? 'WHERE '.$where : '');
        $this->prepare($query);

        foreach ($data as $key => $value) {
            $this->bind(":$key", $value);
        }
        try {
            $this->execute();

            return true;
        } catch (PDOException $e) {
            echo $e->errorInfo[2];

            return false;
        }
    }
953038
public function dbUpdate($table, $data, $condition = '')
    {
        if (is_array($data))
        {
            if (empty($condition)) $condition = 'id';
            $result = Eresus_CMS::getLegacyKernel()->db->
                updateItem($this->__table($table), $data, "`$condition` = '{$data[$condition]}'");
        }
        elseif (is_string($data))
        {
            $result = Eresus_CMS::getLegacyKernel()->db->
                update($this->__table($table), $data, $condition);
        }
        else
        {
            $result = false;
        }

        return $result;
    }
1340962
function update( $table, $data, $where = array(), $params = array() ) {

        if ( empty( $data ) ) return;

        $set = array();

        foreach ( $data as $column => $value ) {

            $set[] = $this->quoteIdentifier( $column ) . " = " . $this->quote( $value );

        }

        if ( !is_array( $where ) ) $where = array( $where );
        if ( !is_array( $params ) ) $params = array_slice( func_get_args(), 3 );

        $table = $this->rewriteTable( $table );
        $query = "UPDATE " . $this->quoteIdentifier( $table );
        $query .= " SET " . implode( ", ", $set );
        $query .= $this->getSuffix( $where );

        $this->onQuery( $query, $params );

        $statement = $this->prepare( $query );
        $statement->execute( $params );

        return $statement;

    }
991421
public function updateByConditions( $data = array(), $conditions = array(), $stripTags = FALSE ){
		if( !( is_array( $data ) && $data ) )
			throw new \InvalidArgumentException( 'Data for update must be an array and have atleast 1 pair' );
		if( !( is_array( $conditions ) && $conditions ) )
			throw new \InvalidArgumentException( 'Conditions for update must be an array and have atleast 1 pair' );

		$updates	= array();
		$conditions	= $this->getConditionQuery( $conditions, FALSE, FALSE, FALSE );					//  render WHERE conditions, uncursored, without functions
		foreach( $this->columns as $column ){
			if( isset( $data[$column] ) ){
				if( $stripTags )
					$data[$column]	= strip_tags( $data[$column] );
				if( $data[$column] == 'on' )
					$data[$column] = 1;
				$data[$column]	= $this->secureValue( $data[$column] );
				$updates[] = '`'.$column.'`='.$data[$column];
			}
		}
		if( sizeof( $updates ) ){
			$updates	= implode( ', ', $updates );
			$query		= 'UPDATE '.$this->getTableName().' SET '.$updates.' WHERE '.$conditions;
			$result		= $this->dbc->exec( $query );
			return $result;
		}
	}
546934
private function updateRecordStatusManyBy($conditions = [], $recordStatus, $method)
    {
        if (count($conditions)) {
            $sets[ 'record_status' ] = $recordStatus;

            if (method_exists($this, 'updateRecordSets')) {
                $this->updateRecordSets($sets);
            }

            if (method_exists($this, $beforeMethod = 'before' . ucfirst($method))) {
                call_user_func_array([&$this, $beforeMethod], [$sets]);
            }

            if ($this->qb->table($this->table)->update($sets, $conditions)) {
                if (method_exists($this, $afterMethod = 'after' . ucfirst($method))) {
                    return call_user_func([&$this, $beforeMethod]);
                }

                return $this->getAffectedRows();
            }
        }

        return false;
    }
772264
public function update($table, array $data, array $conditions, $filter = true)
    {
        if ($filter) {
            $data = $this->filterValues($table, $data);
        }

        if (empty($data)) {
            return 0;
        }

        $farray = array();
        foreach (array_keys($data) as $key) {
            $farray[] = "$key=:$key";
        }

        $carray = array();
        foreach (array_keys($conditions) as $key) {
            $carray[] = "$key=:$key";
        }

        $fields = implode(',', $farray);
        $sql = "UPDATE $table SET $fields WHERE " . implode(' AND ', $carray);

        $stmt = $this->pdo->prepare($sql);

        foreach ($data as $key => $value) {
            $stmt->bindValue(":$key", $value);
        }

        foreach ($conditions as $key => $value) {
            $stmt->bindValue(":$key", $value);
        }

        $stmt->execute();
        $this->executed[] = $sql;
        return $stmt->rowCount();
    }
205094
protected function doUpdateBatch($data, array $conditions)
    {
        !$this->useTransaction ?: $this->db->getTransaction(true)->start();

        try {
            $result = $this->db->getWriter()->updateBatch($this->table, $data, $conditions);
        } catch (\Throwable $e) {
            !$this->useTransaction ?: $this->db->getTransaction(true)->rollback();

            throw $e;
        }

        !$this->useTransaction ?: $this->db->getTransaction(true)->commit();

        return $result;
    }
636435
public function insert(string $table, $data=[]): ?PDOStatement
	{
		if ( ! empty($data))
		{
			$this->set($data);
		}

		return $this->_run('insert', $table);
	}
296495
protected function updateConditions(array $conditions, $table, $alias) {
		$res = [];

		foreach($conditions as $k=>$v) {
			if(is_array($v))
				$v = $this->updateConditions($v, $table, $alias);
			else
				$v = preg_replace('/(?<![\.a-zA-Z0-9-_`\(\)])'.$table.'\./', $alias.'.', $v);
			$k = preg_replace('/(?<![\.a-zA-Z0-9-_`\(\)])'.$table.'\./', $alias.'.', $k);
			$res[$k] = $v;
		}

		return $res;
	}
401304
public function updateById($table, $data, $id = "id")
    {
        // check for id
        if (!isset($data[$id]))
            Throw new \ErrorException("SQL Error: Can't update because of bad data.");

        $options = array('W' => '`' . $id . "`='" . $this->escape($data[$id]) . "'");

        try {
            $this->update($table, $data, $options);
            return $data[$id];
        } catch (\Exception $e) {
            throw $e;
        }
    }