EN English
Version: v2.6.0

id

Return the ID of the last inserted row.

id($name)
Return Value
[string|null] The last insert ID as a string, or null when no ID is available.
$database->insert("account", [
	"user_name" => "foo",
	"email" => "foo@bar.com",
	"age" => 25
]);

$account_id = $database->id();

PostgreSQL

Pass the primary key column as the third argument of insert(). Medoo adds a RETURNING clause and caches the generated value, which is then returned by id(). For a multi-row insert, id() returns the last generated ID.
$database->insert("account", [
	"user_name" => "foo"
], "id");

$account_id = $database->id();
If the primary key is not provided to insert(), id() falls back to PostgreSQL's LASTVAL(). It returns null when the current session has not generated a sequence value. You can still pass a sequence name explicitly when needed.
$account_id = $database->id("account_id_seq");

Oracle

Pass the primary key column as the third argument of insert() so Medoo can return and cache the generated value.
$database->insert("ACCOUNT", [
	"NAME" => "foo"
], "ID");
 
$account_id = $database->id();