8.5.x Connection.php Connection::update($table, array $options = [])
8.0.x Connection.php Connection::update($table, array $options = array())
8.1.x Connection.php Connection::update($table, array $options = array())
8.2.x Connection.php Connection::update($table, array $options = array())
8.3.x Connection.php Connection::update($table, array $options = [])
8.4.x Connection.php Connection::update($table, array $options = [])
8.6.x Connection.php Connection::update($table, array $options = [])

Prepares and returns an UPDATE query object.

Parameters

string $table: The table to use for the update statement.

array $options: (optional) An array of options on the query.

Return value

\Drupal\Core\Database\Query\Update A new Update query object.

See also

\Drupal\Core\Database\Query\Update

File

core/lib/Drupal/Core/Database/Connection.php, line 857

Class

Connection
Base Database API class.

Namespace

Drupal\Core\Database

Code

public function update($table, array $options = array()) {
  $class = $this
    ->getDriverClass('Update');
  return new $class($this, $table, $options);
}

Comments

pedrodacosta’s picture

Here's an example of how to update a record using this method

      // Let's say that you want to do something like this:
      // UPDATE items SET value = 5 WHERE id = 10

      // then the corresponding code would be:

      $db = \Drupal::database();

      $db->update('items')->fields(
        array(
          'value' => 5
        )
      )
      ->condition('id', 10, '=')
      ->execute();