function Connection::lastInsertId

Same name in this branch
  1. 11.x core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::lastInsertId()
Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::lastInsertId()
  2. 10 core/lib/Drupal/Core/Database/Connection.php \Drupal\Core\Database\Connection::lastInsertId()

Returns the ID of the last inserted row or sequence value.

This method should normally be used only within database driver code.

This is a proxy to invoke lastInsertId() from the wrapped connection. If a sequence name is not specified for the name parameter, this returns a string representing the row ID of the last row that was inserted into the database. If a sequence name is specified for the name parameter, this returns a string representing the last value retrieved from the specified sequence object.

Parameters

string|null $name: (Optional) Name of the sequence object from which the ID should be returned.

Return value

string The value returned by the wrapped connection.

Overrides Connection::lastInsertId

File

core/modules/mysqli/src/Driver/Database/mysqli/Connection.php, line 173

Class

Connection
MySQLi implementation of \Drupal\Core\Database\Connection.

Namespace

Drupal\mysqli\Driver\Database\mysqli

Code

public function lastInsertId(?string $name = NULL) : string {
  return (string) $this->connection->insert_id;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.